c# - List of foreign keys in Entity Framework Core using SQLite -
i want implement related pages structure 1 page have list of other pages related it. could't figure out if possible. have structure this:
public class page { public int id { get; set; } public string urlname { get; set; } public list<relatedpages> relpages1 { get; set; } } public class relatedpages { public int id { get; set; } public int pageid { get; set; } public page page { get; set; } // list of related page ids public list<int> relpagesid { get; set; } public list<page> relpages { get; set; } }
and here onmodelcreating method in dbcontext:
protected override void onmodelcreating(modelbuilder modelbuilder) { modelbuilder.entity<relatedpages>() .hasone(x => x.page) .withmany(x => x.relpages1) .hasforeignkey(x => x.pageid); }
if trying recursive selection such ef load records in turn same table don't think possible. otherwise structure should work fine.
Comments
Post a Comment