我试图向下过滤三个子级别,并仅查找PropertyMailingAddress.Status == True的子元素。
如何将过滤器转换为三个级别并使用EntityFrameworkPlus IncludeFilter进行嵌套过滤?最有效的方法是什么?
类结构是这样嵌套的:
这种原始方式不起作用:
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尝试有效的方式:是否必须重新嵌套最后一行,使其上方或下方的嵌套位置正确?
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
您不能Include
与混在一起IncludeFilter
。
在EF Core中,会IncludeFilter
自动添加所有路径。
我们没有类的定义,因此很难确切地知道这种关系,但是查询应如下所示:
var result = await db.Property.IncludeFilter(pm => pm.PropertyParty
.Select(x => x.Party)
.SelectMany(x => x.PartyMailingAddress)
.SelectMany(x => x.PropertyMailingAddress.Where(z => z.Status == true)).ToListAsync();
过滤是在数据库中完成的。因此,请谨慎使用EF Core 2.x,因为他们在EF Core 3.x中删除了客户端评估,这导致了一些问题。
如果您需要更多帮助,只需在我们的问题跟踪器中提供可运行的解决方案:https : //github.com/zzzprojects/EntityFramework-Plus/issues
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句