英文:
System.InvalidOperationException: 'The LINQ expression 'u => (Guid?)u == EntityShaperExpression:
问题
var projects = _projectRepo.FindAll(x => listProjectIds.Any(u => u == x.Id)).ToList();
// .FindAll() 返回 IQueryable<T>
// listProjectIds 是一个 List<Guid>()
下面是调试时显示的错误信息:
System.InvalidOperationException: 'LINQ 表达式 'u => (Guid?)u == EntityShaperExpression:
DataApp.Entities.Project
ValueBufferExpression:
ProjectionBindingExpression: EmptyProjectionMember
IsNullable: False
.Id' 无法被翻译。请重新编写查询以便进行翻译,或明确切换到客户端评估,通过插入 'AsEnumerable'、'AsAsyncEnumerable'、'ToList' 或 'ToListAsync' 的调用。有关更多信息,请参阅 https://go.microsoft.com/fwlink/?linkid=2101038。'
请帮我解决这个问题!
英文:
var projects = _projectRepo.FindAll(x => listProjectIds.Any(u => u == x.Id)).ToList();
// .FindAll() return IQueryable<T>
// listProjectIds as a List<Guid>()
The following error is showing on debug
System.InvalidOperationException: 'The LINQ expression 'u => (Guid?)u == EntityShaperExpression:
DataApp.Entities.Project
ValueBufferExpression:
ProjectionBindingExpression: EmptyProjectionMember
IsNullable: False
.Id' 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 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.'
Please help me solve this problem!
答案1
得分: 0
将Any
更改为Contains
:
var projects = _projectRepo
.FindAll(x => listProjectIds.Contains(x.Id))
.ToList();
英文:
Change Any
to Contains
:
var projects = _projectRepo
.FindAll(x => listProjectIds.Contains(x.Id))
.ToList();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论