[英]EfCore ToListAsync() Throw exception with where condition
我有一个异步任务有问题,该任务从具有特定条件的数据库中获取项目当我调用ToListAsync()时出现此错误
类型'System.Collections.Generic.IAsyncEnumerable
1[System.Guid]' cannot be used for constructor parameter of type 'System.Collections.Generic.IEnumerable
表达式1[System.Guid]' cannot be used for constructor parameter of type 'System.Collections.Generic.IEnumerable
1 [System.Guid]'的1[System.Guid]' cannot be used for constructor parameter of type 'System.Collections.Generic.IEnumerable
参数名称:arguments [0]
这是代码片段:
public async Task<IEnumerable<Parent>> GetItems(List<Guid> TypeIds)
{
var items = context.Parent.Include(x => x.Child).Where(x => new HashSet<Guid>(x.Child.Select(y => y.TypeId).Distinct()).SetEquals(new HashSet<Guid>(TypeIds)));
return await items.Include(x=> x.Child).ToListAsync();
}
如果我实现此方法不是async
我将不会收到错误消息,并且一切正常。
您不能像实体框架那样拥有Where
lambda,请记住该表达式将被转换为SQL,而该SQL不知道HashSet
是什么。 您可能正在寻找这样的东西:
var items = context.Parent
.Include(x => x.Child)
.Where(x => x.Child.Any(y => TypeIds.Contains(y.TypeId)));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.