List of foreign keys in Entity Framework Core using SQLite

c# entity-framework entity-framework-core sqlite

Question

One page should include a list of additional pages that are connected to it, according to the Related Pages structure I wish to use. But I was unable to determine if it was feasible. I now have the following structure:

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; }
    // I would like this to be the list of related page IDs 
    public List<int> RelPagesID { get; set; }
    public List<Page> RelPages { get; set; }
}

And here is my DbContext's OnModelCreating method:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
            modelBuilder.Entity<RelatedPages>()
                        .HasOne(x => x.Page)
                        .WithMany(x => x.RelPages1)
                        .HasForeignKey(x => x.PageID);

}
1
0
8/8/2016 1:32:59 PM

Popular Answer

ZZZ_tmp
0
8/8/2016 1:44:40 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow