Include Grandchildren in EF Query

前端 未结 2 554
死守一世寂寞
死守一世寂寞 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:30

    Sure, you can do

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

    See MSDN, caption Remarks, the fifth bullet.

提交回复
热议问题