System.InvalidOperationException: ‘LINQ表达式 ‘u => (Guid?)u == EntityShaperExpression:

huangapple go评论60阅读模式
英文:

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 =&gt; listProjectIds.Any(u =&gt; u == x.Id)).ToList();
// .FindAll() return IQueryable&lt;T&gt;
// listProjectIds as a List&lt;Guid&gt;()

The following error is showing on debug

System.InvalidOperationException: &#39;The LINQ expression &#39;u =&gt; (Guid?)u == EntityShaperExpression: 
    DataApp.Entities.Project
    ValueBufferExpression: 
        ProjectionBindingExpression: EmptyProjectionMember
    IsNullable: False
.Id&#39; 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 &#39;AsEnumerable&#39;, &#39;AsAsyncEnumerable&#39;, &#39;ToList&#39;, or &#39;ToListAsync&#39;. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.&#39;

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 =&gt; listProjectIds.Contains(x.Id))
     .ToList();

huangapple
  • 本文由 发表于 2023年4月4日 18:05:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/75928089.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定