IQueryable.Include() gets ignored

前端 未结 2 820
春和景丽
春和景丽 2021-01-19 07:35

I have Parent and Child entities related to each other as 1 to M. I need to query childs together with parents within a single SQL query, but the <

2条回答
  •  粉色の甜心
    2021-01-19 07:53

    As you're creating an anonymous object the Parent DbSet Set() of the context is not being populated with any data and therefore neither are the Children being stored in the context. One solution could be to add the children to the anonymous object but I'm not sure this would cause them to be added to the Set DbSet.

    var r2 = ctx.Set()
       .Include(p => p.Childs)
       .Where(p => p.Id == 2)
       .Select(p => new { myParent = p, children = p.Childs })
       .ToList();
    

提交回复
热议问题