Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# EF Core 2.1 Linq查询到EF Core 3.0_C#_Entity Framework_Linq_Entity Framework Core_Ef Core 3.0 - Fatal编程技术网

C# EF Core 2.1 Linq查询到EF Core 3.0

C# EF Core 2.1 Linq查询到EF Core 3.0,c#,entity-framework,linq,entity-framework-core,ef-core-3.0,C#,Entity Framework,Linq,Entity Framework Core,Ef Core 3.0,我正在处理一个我无法在ef core 3.0上运行的查询,它在2.1版本中运行良好,我想如果有人能帮助我了解如何在3.0版本中运行它 让我从挑战开始 我有一个名为Zone的表,它与名为Bin的表有一对多关系,Bin与名为BinItems的表有一对多关系,BinItem与名为PlanItem的表有一对一关系,PlanItem与名为Plan的表有一对一关系 因此,我希望获得计划表中所有计划的列表,但它必须满足以下条件:计划项位于指定区域列表的区域中。假设我有一个ZoneID列表,并且我正在寻找所有与

我正在处理一个我无法在ef core 3.0上运行的查询,它在2.1版本中运行良好,我想如果有人能帮助我了解如何在3.0版本中运行它

让我从挑战开始

我有一个名为Zone的表,它与名为Bin的表有一对多关系,Bin与名为BinItems的表有一对多关系,BinItem与名为PlanItem的表有一对一关系,PlanItem与名为Plan的表有一对一关系

因此,我希望获得计划表中所有计划的列表,但它必须满足以下条件:计划项位于指定区域列表的区域中。假设我有一个ZoneID列表,并且我正在寻找所有与之相关的bin项目位于该区域内的计划

这是我在2.1版本中使用的查询,在迁移到3.0之前一直有效

var filterQuery = _PlanRepository.Table;
filterQuery = filterQuery.Where(x => x.Items.Where(o => o.BinItem != null 
                                         && o.BinItem.Bin != null
                                         && o.BinItem.Bin.Zone != null)
                                 .Select(y => y.BinItem.Bin.Zone.Id)
                                 .Intersect(PlanFilter.WarehouseIds).Any());

var finalQuery = filterQuery
                     .Include(x => x.Items)
                           .ThenInclude(x => x.BinItem)
                           .ThenInclude(x => x.Bin)
                           .ThenInclude(x => x.Zone)
                           .AsQueryable();
这给了我一个如下的错误

System.InvalidOperationException:处理LINQ表达式“Intersect” 资料来源1:选择 资料来源:何处 来源:AsQueryableMaterializeCollectionNavigationNavigation:Plan.Items k__BackingField,ICollection集合到Dependent Plan项目反向:Plan,其中 来源:NavigationExpression 来源:Where,Bin>,仓库部分>> 来源:LeftJoin,Bin>,WarehouseSection,Nullable,TransparentIdentifier,Bin>,WarehouseSection>> 外部:LeftJoin、Bin、可空、透明标识符、Bin>> 外部:LeftJoin,TransparentIdentifier> 外:在哪里 资料来源:DbSet, 谓词:p0=>Property>Unhandled参数:p,Id==Property>p0,PlanId, 内部:DbSet, outerKeySelector:p0=>Property>p0,BinItemId, innerKeySelector:b=>Property>b,Id, 结果选择器:o,i=>newtransparentIdentifier 外部=o, 内部=i , 内部:DbSet, outerKeySelector:p0=>Property>p0.Inner,BinId, innerKeySelector:b0=>Property>b0,Id, 结果选择器:o,i=>新的透明标识符,Bin> 外部=o, 内部=i , 内部:DbSet, outerKeySelector:p0=>Property>p0.Inner,ZoneId, innerKeySelector:w=>Property>w,Id, 结果选择器:o,i=>新的透明标识符,Bin>,仓库部分> 外部=o, 内部=i , 谓词:p0=>Property>p0.Outer.Outer.Inner,Id!=null&&Property>p0.Outer.Inner,Id!=null&&Property>p0.internal,Id!=无效的 PendingSelector:p0=>NavigationTreeExpression 值:EntityReferencePlanItem 表达式:p0.Outer.Outer.Outer.BinItem.Bin.Zone.Id , 谓词:i=>Property>NavigationTreeExpression 值:EntityReferencePlan 表达式:未处理的参数:p,Id==Property>i,PlanId, 谓词:o=>Property>o.BinItem,Id!=null&&Property>o.BinItem.Bin,Id!=null&&Property>o.BinItem.Bin.Zone,Id!=无效的 选择器:y=>y.BinItem.Bin.Zone.Id, source2:未处理的参数:“'NavigationExpandingExpressionVisitor'的\uu平面过滤器\u仓库ID_0”失败。这可能表明EF核心中存在缺陷或限制。有关更多详细信息,请参阅。 在Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.VisitMethodCallMethodCallExpression methodCallExpression中 在Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.VisitMethodCallMethodCallExpression methodCallExpression中 在Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.ExpandNavigationInExpressionNavigationExpansionExpression源中,显示表达式表达式 在Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.ProcessWhere NavigationExpansionExpression源中,LambdaExpression谓词

有人能和我分享一下如何在Ef core 3.0版本中实现这一点吗?

好的,我想出来了

这是我的新代码

                query = query.Where(x => x.Items.Where(o => o.BinItem != null
                                                     && o.BinItem.Bin != null
                                                     && o.BinItem.Bin.Zone != null
                                                     && PlanFilter.WarehouseIds.Contains(o.BinItem.Bin.Zone.Id)).Any());
好的,我知道了

这是我的新代码

                query = query.Where(x => x.Items.Where(o => o.BinItem != null
                                                     && o.BinItem.Bin != null
                                                     && o.BinItem.Bin.Zone != null
                                                     && PlanFilter.WarehouseIds.Contains(o.BinItem.Bin.Zone.Id)).Any());

这可能有助于@tukaef谢谢,我看到了,但我真正的问题是如何处理这件事,我只是想不出如何让它再次发挥作用。这可能有助于@tukaef谢谢,我看到了,但我真正的问题是如何处理这件事,我只是想不出如何让它再次发挥作用。