Reinstantiating EF classes with one-to-many relationship and compound key of strings

前端 未结 1 1498
[愿得一人]
[愿得一人] 2021-01-26 18:42

I have the following EF Code First classes, which appear to be working to a point. I also have Initialization code that seeds these tables with data from elsewhere that is leng

相关标签:
1条回答
  • 2021-01-26 18:45

    Why SubCategories is null or with 0 item because you don't include this relation that it is Eager loading. if you want to use lazy loading you can use virtual keyword in your navigation property:

    Lazy Loading:

    public virtual List<SubCategory> SubCategories { get; set; }
    

    Eager Loading:

    db.Categories.Where(c => c.CategoryCode == "FUND").Include(x => x.SubCategories ).ToList();
    

    Read More.

    0 讨论(0)
提交回复
热议问题