简体   繁体   English

EF Core:无法翻译 LINQ 表达式 - Net Core 3.1

[英]EF Core: The LINQ expression could not be translated - Net Core 3.1

I am trying to implement a query to find all Conditions in each Site that match the assigning user's conditions and delete them - excluding the ones that don't match.我正在尝试实施查询以查找每个站点中与分配用户的条件匹配的所有条件并删除它们 - 排除不匹配的条件。

var savedPartnerConditions = eipDbContext.EIP_User_Partner_Condition.Where(savedCondition => savedCondition.EIP_User_Partner_Id == savedPartner.EIP_User_Partner_Id && existingUser.CurrentUserConditions.Any(condition => condition.Code == savedCondition.Code));

eipDbContext.EIP_User_Partner_Condition.RemoveRange(savedPartnerConditions);

But the query cannot be translated resulting in the following error:但查询无法翻译,导致以下错误:

.Any(condition => condition.Code == e.Code))' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync()

How can I contruct the query to fix the error?如何构造查询以修复错误?

I was able to fix this with the following code that seems to work:我能够使用以下似乎有效的代码解决此问题:

var selectionResultSet = eipDbContext2.EIP_User_Partner_Condition.Where(savedCondition => savedCondition.EIP_User_Partner_Id == savedPartner.EIP_User_Partner_Id).ToList();

var savedPartnerConditions = selectionResultSet
.AsEnumerable()
.Where (savedCondition => (existingUser.CurrentUserConditions.Any(condition => condition.Code == savedCondition.Code)));

eipDbContext3.EIP_User_Partner_Condition.RemoveRange(savedPartnerConditions);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 EF Core 3.1 - 无法翻译 LINQ 表达式(左连接与 group by) - EF Core 3.1 - The LINQ expression could not be translated (left joins with group by) EF Core:无法翻译 LINQ 表达式 - EF Core: The LINQ expression could not be translated 无法翻译 LINQ 表达式。 以可翻译的形式重写查询,或切换到客户端评估 EF Core 3.1 - The LINQ expression could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation EF Core 3.1 EF Core 更新 LINQ 表达式“x”无法翻译 - EF Core Update The LINQ expression 'x' could not be translated .NET 核心运行时错误:LINQ 表达式无法翻译 - .NET Core runtime error: LINQ expression could not be translated EF Core:无法为具有通用 StartsWith() 表达式的嵌套列表翻译 LINQ 表达式 - EF Core: The LINQ expression could not be translated for a nested List with Generic StartsWith() Expression EF Core Linq 到 SQLite 无法翻译,适用于 SQL 服务器 - EF Core Linq to SQLite could not be translated, works on SQL Server 无法翻译 EF 核心查询 - EF core query could not be translated Entity Framework Core 抛出异常:无法使用 PostgreSQL 翻译 LINQ 表达式 - Entity Framework Core Throwing Exception: The LINQ expression could not be translated with PostgreSQL LINQ 表达式中的 OData $top 查询无法转换,将使用 EF Core 和 .NET Core 2.2 在本地进行评估 - OData $top query in LINQ expression could not be transalted and will be evaluated locally using EF Core and .NET Core 2.2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM