我正在处理一个我无法在ef核心3.0上工作的查询,它在2.1版本中运行得很好,我想如果有人能帮我弄清楚我如何在3.0版本中工作。
所以让我从挑战开始。
我有一个名为Zone的表,它与一个名为Bin的表有一对多的关系,bin与一个名为BinItems的表有一对多的关系,而BinItem与一个名为PlanItem的表有一对一的关系,PlanItem与一个名为PlanItem的表有一对一的关系。
因此,我希望在计划表中获得所有计划的列表,但它必须满足计划项位于指定区域列表的区域的条件。因此,假设我有一个ZoneIds的列表,我正在寻找所有的计划,他们相关的垃圾箱项目在该区域内。
下面是我在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表达式的相交处理( source1: Select(来源:Where: Where(来源:System.InvalidOperationException Plan.Items (k__BackingField,ICollection) )集合ToDependent PlanItem逆: Plan,source1(来源: NavigationExpansionExpression source: Where,Bin>,WarehouseSection>>)(来源: LeftJoin,Bin>,WarehouseSection,Nullable,TransparentIdentifier,Bin>WarehouseSection>>(外部: LeftJoin,Bin,Nullable,TransparentIdentifier,Bin>>(外部: LeftJoin,TransparentIdentifier>)谓词:(p0) => Property>((未处理的参数: p),"Id") == Property>(p0,“PlanId”),内部: DbSet,outerKeySelector:(p0) => Property>(p0,BinItemId)innerKeySelector:(b) => Property>(b,"Id"),resultSelector:(o,i) => new TransparentIdentifier(外层= o,),内部: DbSet,outerKeySelector:(p0) => Property>(p0.side,"BinId"),innerKeySelector:(b0) => Property>(b0,"Id"),resultSelector:(o,i) => new TransparentIdentifier,Bin>(外层= o,),内部: DbSet,outerKeySelector:(p0) => Property>(p0.inent,"ZoneId"),innerKeySelector:(w) => Property>(w,"Id"),resultSelector:(o,i) =>新TransparentIdentifier,Bin>,WarehouseSection>(外层= o,Inner =i),谓词:(p0) => Property>(p0.Outer.Outer.Inner,) != null && Property>(p0.Outer.Inner,"Id") != null &Property>(p0.side,"Id") != null) PendingSelector:(p0) => NavigationTreeExpression值: EntityReferencePlanItem表达式:p0.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") != null),选择器:(y) => y.BinItem.Bin.Zone.Id),source2:(未处理的参数:__PlanFilter_WarehouseIds_0)‘by 'NavigationExpandingExpressionVisitor’failed。这可能表示EF中存在缺陷或限制。有关更多详细信息,请参见https://go.microsoft.com/fwlink/?linkid=2101433。(在Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)在Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)在Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.ExpandNavigationsInExpression(NavigationExpansionExpression源,表达式表达式)在Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.ProcessWhere(NavigationExpansionExpression源,LambdaExpression谓词)
有人能分享我如何让这个在Ef核心3.0版本工作吗?
发布于 2019-12-04 20:20:42
好吧,我想出来了。
这是我的新代码。
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());https://stackoverflow.com/questions/59182991
复制相似问题