Loading Nested Entities / Collections with Entity Framework

后端 未结 2 1041
离开以前
离开以前 2020-12-14 19:05

I am trying to Eagerly load all the related entities or collection of Entity in one call. My Entities Looks like:

Class Person
{
    public virtual long Id {         


        
2条回答
  •  囚心锁ツ
    2020-12-14 19:26

    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();
    

提交回复
热议问题