Open keatkeat87 opened 5 years ago
@keatkeat87 I think the expanded item "User" needs to be prefixed with a qualified type name "Character" on which the selected item is defined. It also explains why OK(Db.Characters) works since User is defined on Character type. Can you please provide additional information so that the issue can be examined further? I got the following error after git clone.
c:\github\myTemp\aspnet-core-odata-delived-class-expand-issue>dotnet restore
Restoring packages for c:\github\myTemp\aspnet-core-odata-delived-class-expand-issue\ODataDelivedExpandIssue\ODataDelivedExpandIssue.csproj...
c:\github\myTemp\aspnet-core-odata-delived-class-expand-issue\ODataDelivedExpandIssue\ODataDelivedExpandIssue.csproj : warning NU1608: Detected package version outside of dependency constraint: Microsoft.AspNetCore.App 2.1.0 requires Microsoft.AspNetCore.Razor
.Design (= 2.1.0) but version Microsoft.AspNetCore.Razor.Design 2.1.2 was resolved. [c:\github\myTemp\aspnet-core-odata-delived-class-expand-issue\ODataDelivedExpandIssue.sln]
c:\github\myTemp\aspnet-core-odata-delived-class-expand-issue\ODataDelivedExpandIssue\ODataDelivedExpandIssue.csproj : warning NU1608: Detected package version outside of dependency constraint: Microsoft.AspNetCore.App 2.1.0 requires Microsoft.EntityFrameworkC
ore.InMemory (= 2.1.0) but version Microsoft.EntityFrameworkCore.InMemory 2.1.4 was resolved. [c:\github\myTemp\aspnet-core-odata-delived-class-expand-issue\ODataDelivedExpandIssue.sln]
c:\github\myTemp\aspnet-core-odata-delived-class-expand-issue\ODataDelivedExpandIssue\ODataDelivedExpandIssue.csproj : error NU1107: Version conflict detected for Microsoft.AspNetCore.Razor.Language. Reference the package directly from the project to resolve t
his issue. [c:\github\myTemp\aspnet-core-odata-delived-class-expand-issue\ODataDelivedExpandIssue.sln]
c:\github\myTemp\aspnet-core-odata-delived-class-expand-issue\ODataDelivedExpandIssue\ODataDelivedExpandIssue.csproj : error NU1107: ODataDelivedExpandIssue -> Microsoft.VisualStudio.Web.CodeGeneration.Design 2.1.1 -> Microsoft.VisualStudio.Web.CodeGenerators
.Mvc 2.1.1 -> Microsoft.VisualStudio.Web.CodeGeneration 2.1.1 -> Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore 2.1.1 -> Microsoft.VisualStudio.Web.CodeGeneration.Core 2.1.1 -> Microsoft.VisualStudio.Web.CodeGeneration.Templating 2.1.1 -> Micros
oft.AspNetCore.Razor.Language (>= 2.1.1) [c:\github\myTemp\aspnet-core-odata-delived-class-expand-issue\ODataDelivedExpandIssue.sln]
c:\github\myTemp\aspnet-core-odata-delived-class-expand-issue\ODataDelivedExpandIssue\ODataDelivedExpandIssue.csproj : error NU1107: ODataDelivedExpandIssue -> Microsoft.AspNetCore.App 2.1.0 -> Microsoft.AspNetCore.Razor.Language (= 2.1.0). [c:\github\myTemp\
aspnet-core-odata-delived-class-expand-issue\ODataDelivedExpandIssue.sln]
Generating MSBuild file c:\github\myTemp\aspnet-core-odata-delived-class-expand-issue\ODataDelivedExpandIssue\obj\ODataDelivedExpandIssue.csproj.nuget.g.props.
Restore failed in 721.15 ms for c:\github\myTemp\aspnet-core-odata-delived-class-expand-issue\ODataDelivedExpandIssue\ODataDelivedExpandIssue.csproj.
hi Bill,
for the dotnet restore error, i don't know what is this, so sorry for that. but i just commit all the dependencies, please try git clone again then skip dotnet restore part. hope it can work.
as you said, the User need to add prefix type. so i try do this, but still not working. http://localhost:62710/odata/admins?$expand=ODataDelivedExpandIssue.Models.Character/User
hi @biaol-odata , is this something further updated? have you successfully run my environment?
Short summary (3-5 sentences) describing the issue. $expand not working in derived class
Assemblies affected
asp.net core 2.1.1 odata 7.1.0
Reproduce steps
git clone https://github.com/keatkeat87/aspnet-core-odata-delived-class-expand-issue.git dotnet restore dotnet ef migrations add Init dotnet ef database update (note: it will create demo database ODataDelivedExpandIssue in mssqllocaldb) F5 start run application visit url : http://localhost:57987/odata/admins (note: port maybe different) it will get the right result, but when i add $expand http://localhost:57987/odata/admins?$expand=User this will fail and response nothing.
Optional, details of the root cause if known. Delete this section if you have no additional details to add. similar issue https://github.com/OData/WebApi/issues/1530
Some code here : Model.cs ` public class AccountContext : DbContext { public AccountContext(DbContextOptions options)
: base(options)
{ }
public DbSet Users { get; set; }
public DbSet Characters { get; set; }
public DbSet Admins { get; set; }
public DbSet Members { get; set; }
}
Startup.cs `private static IEdmModel GetEdmModel() { ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); builder.EntitySet< User >("Users"); builder.EntitySet< Character >("Characters"); builder.EntitySet< Admin >("Admins"); builder.EntitySet< Member >("Members"); return builder.GetEdmModel(); } public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseCookiePolicy(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}");
}`
Controller : `public class AdminsController : ODataController { private AccountContext Db; public AdminsController( AccountContext db ) { Db = db; }
}`
if you need anything more to make sure this is a bug or whatever please let me know.