[英]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.