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

强颜欢笑 提交于 2019-12-02 08:23:52

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!