【发布时间】:2020-05-27 01:13:55
【问题描述】:
我正在尝试向下过滤三个子级别并仅查找 PropertyMailingAddress.Status== True 的子元素。
如何将过滤器向下转换三个级别并使用 EntityFrameworkPlus IncludeFilter 进行嵌套过滤?什么是最有效的方法?
类结构嵌套如下:
- 财产
- 物业方
- 聚会
- 派对邮寄地址
- 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
【问题讨论】:
-
你能附加你的类定义吗?
标签: c# .net linq .net-core entity-framework-plus