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