entity-framework - EF Core:无法翻译 LINQ 表达式 - Net Core 3.1
问题描述
我正在尝试执行查询以查找每个站点中与分配用户条件匹配的所有条件并将其删除 - 不匹配的条件除外。
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);
但是无法翻译查询,导致以下错误:
.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()
如何构建查询以修复错误?
解决方案
我能够使用以下似乎可行的代码来解决此问题:
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);
推荐阅读
- java - 每个线程中相同键的线程安全集合或并发
- tensorflow - 如何向我在 Google Cloud 上部署的模型发送带有图像的测试请求?
- c - C中的所有最小Levenshtein距离解
- python-3.x - 如何在 Pyspark 函数“Withcolumn”中传递列表
- python - 在 Visual Studio Code 中运行 Python 代码有困难,在 Python shell 中运行,但不在此处
- xml - 如何通过将 xslt 导入另一个 xslt 来获取输入值?
- macos - 使用 docker 在 Mac 和 nginx 中安装 Nginx
- python - 是否可以检查计算机是否使用 python 连接到域?
- python - 康威的生命游戏推进网格(与上一个不同!)
- javascript - 可以设置网站的加载时间吗?