I am trying to filter three child levels down and find only child elements where PropertyMailingAddress.Status== True.
How do I convert filter three levels down and conduct nested filtering with EntityFrameworkPlus IncludeFilter? What is the most efficient way?
Class Structure is nested like this:
- Property
- PropertyParty
- Party
- PartyMailingAddress
- PropertyMailingAddress <--- Status should equal true (Any grandchild PropertyMailingAddress nodes with Status == False, should be removed from this nested grandchild branch, keep the PropertyMailingAddress nodes which are True)
This original way is not working:
var result = await db.Property.Include(pm => pm.PropertyParty)
.Include(pm => pm.PropertyParty)
.ThenInclude(x => x.Party)
.ThenInclude(x => x.PartyMailingAddress)
.ThenInclude(x => x.PropertyMailingAddress)
.Where(a => a.PropertyParty.Any(x => (x.Party.PartyMailingAddress.Any(z => z.PropertyMailingAddress.Any(h => h.Status == true))))).ToListAsync();
Trying efficient way with Entity Framework Plus: Does the last line have to be relink joined again with nested wheres above, or is below fine?
var result = await db.Property.Include(pm => pm.PropertyParty)
.Include(pm => pm.PropertyParty)
.ThenInclude(x => x.Party)
.ThenInclude(x => x.PartyMailingAddress)
.ThenInclude(x => x.PropertyMailingAddress)
.IncludeFilter(y => y.PropertyMailingAddress.Where(z => z.Status == true)).ToListAsync();
*We will require all the nested entities, while filtering,
Currently using Net Core 2.2