How do I do a eager query of a parent child relationship that:
- filters a on child fields
- sorts on both parent and child
- return a List or Parents with the children pre-populated
If I try
from p in _context.Parents.Include("children")
join c in _context.childrenon p.Id equals c.ParentId
where d.DeletedDate == null
orderby p.Name ascending, c.Name
select p
Then I get the Parent object back but each Parent has NULL for children
if I try
from p in _context.Parents.Include("children")
orderby p.Name ascending
select p
The query returns all Parents and children but they are not filtered or sorted.
The result I want back is a IEnumerable<Parent>
i.e.
Parent[0].name = "foo"
Parent[0].children = IEnumerable<Child>
Parent[1].name = "bar"
Parent[1].children = IEnumerable<Child>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…