Loading Nested Entities / Collections with Entity Framework

你说的曾经没有我的故事 提交于 2019-11-28 21:21:12

You can try this:

Context.Employees
    .Include(e => e.Person)
    .Include(e => e.Titles.Select(t => t.Title))
    .ToList();

Select can be applied to a collection and loads navigation properties of the next level in the object graph.

Since this is the first page in my search in google, I just wanted to post this.

Slauma's answer is fine. But it's recommended to use Load() instead of ToList() if you don't plan to actually use the list. So it would be:

    Context.Employees
        .Include(e => e.Person)
        .Include(e => e.Titles.Select(t => t.Title))
        .Load();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!