i've started working ef. have simple models page
, related pages
.
public class page { public int id { get; set; } [required] public string urlname { get; set; } [required] public string title { get; set; } public list<relatedpages> relpages1 { get; set; } public list<relatedpages> relpages2 { get; set; } } public class relatedpages { public int id { get; set; } public int page1id { get; set; } public page page1 { get; set; } public int page2id { get; set; } public page page2 { get; set; } }
this in dbcontext:
protected override void onmodelcreating(modelbuilder modelbuilder) { modelbuilder.entity<page>().hasindex(x => x.urlname).isunique(); modelbuilder.entity<relatedpages>().hasone(x => x.page1).withmany(x => x.relpages1).hasforeignkey(x => x.page1id); modelbuilder.entity<relatedpages>().hasone(x => x.page2).withmany(x => x.relpages2).hasforeignkey(x => x.page2id); }
though when try execute command
dbcontext.pages.where(x => x.relpages1 != null);
i have exception
invalidoperationexception: property 'page1id' on entity type 'page' not found. ensure property exists , has been included in model.
this appears bug in ef core. can file issues @ https://github.com/aspnet/entityframework/issues.
if trying query set of pages have @ least 1 relpages1, linq query doesn't have same bug , returns expect result is:
dbcontext.pages.where(x => x.relpages1.count() > 0)
Comments
Post a Comment