使用EntityFrameworkPlus IncludeFilter在ThenInclude上进行过滤

用户名

我试图向下过滤三个子级别,并仅查找PropertyMailingAddress.Status == True的子元素。

如何将过滤器转换为三个级别并使用EntityFrameworkPlus IncludeFilter进行嵌套过滤?最有效的方法是什么?

类结构是这样嵌套的:

  1. 属性
  2. 产权方
  3. 派对
  4. PartyMailingAddress
  5. PropertyMailingAddress <---状态应等于true(状态为== False的任何孙子PropertyMailingAddress节点,应从此嵌套的孙子分支中删除,并保持PropertyMailingAddress节点为True)

这种原始方式不起作用:

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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

查询需要在.ThenInclude之后使用.Where子句进行过滤

如何使用OData在Dictionary <string,string>上进行$ filter过滤?

使用Fresco在替换图像上进行SimpleDraweeView黑色过滤

在布尔列上进行过滤时在熊猫中使用FutureWarning

使用输入过滤器在 Div 上进行实时搜索

如何使用Get-WmiObject在进程“命令行”上进行过滤

如何使用输入过滤器在Div上进行实时搜索

根据索引或使用lambda进行的最后一个数组值修改在Java Stream上进行过滤

自从MySQL 5.6-> 5.7以来,MySQL JOIN并未使用<>运算符在WHERE子句上进行过滤

使用树过滤器从Git提交中删除敏感数据并在macOS上进行sed

使用SyncAdapter在Android上进行双向同步

使用python在Android上进行网页抓取

使用Pandas在列上进行多个聚合

Java使用HashMap在ArrayList上进行迭代

使用sed在单行上进行多次替换

使用hciattach在uart上进行蓝牙?

使用 jsonb 在 postgres 上进行 EAV

使用 MultiIndex 在轴上进行基本索引

使用NEST在ElasticSearch上进行批量更新

如何使用 Pandas 在 datetimeindex 上进行连接?

使用NextJS + Express在localhost上进行HTTPS

使用WSL在VSCode上进行ESLint

使用javascript在AxisX上进行多个分组

使用Keras模型在Android上进行分类

使用Windows在Docker上进行清漆

使用Postman在Swift上进行用户注册

使用img元素在Div上进行Div

使用LACP在RedHat 6上进行绑定

使用JotForm在离线表单上进行制作