Include Grandchildren in EF Query

前端 未结 2 555
死守一世寂寞
死守一世寂寞 2020-12-03 21:05

Given the object hierarchy

public class Parent
{
    public int Id { get; set; }
    public virtual Child Child { get; set; }
}

public class Child
{
    pub         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-03 21:10

    Update: If you are using Entity Framework Core you should use the following syntax

    var hierarchy = from p in ctx.Parents
                        .Include(p => p.Children)
                        .ThenInclude(c => c.GrandChild)
                    select p;
    

提交回复
热议问题