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()

Как я могу составить запрос, чтобы исправить ошибку?


person John Bowyer    schedule 27.02.2020    source источник


Ответы (1)


Мне удалось исправить это с помощью следующего кода, который, похоже, работает:

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);
person John Bowyer    schedule 27.02.2020