我正在尝试向下过滤三个子级别,并仅找到 PropertyMailingAddress.Status== True 的子元素。
如何将过滤器向下转换三个级别并使用 EntityFrameworkPlus IncludeFilter 进行嵌套过滤?最有效的方法是什么?
类结构嵌套如下:
- 财产
- 财产党
- 聚会
- 聚会邮寄地址
- PropertyMailingAddress <--- 状态应该等于真(任何状态 == False 的孙子 PropertyMailingAddress 节点,都应该从此嵌套的孙子分支中删除,保留为 True 的 PropertyMailingAddress 节点)
这种原始方式不起作用:
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();
尝试使用 Entity Framework Plus 的有效方法:最后一行是否必须重新链接并再次与上面的嵌套 wheres 连接,或者是否可以?
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();
*我们将需要所有嵌套实体,同时过滤,
目前使用的是 Net Core 2.2