[英]LINQ in Entity Framework 6 with large .Any()
I have a EF6 query that takes a list of IDs and does a query: 我有一个EF6查询,它获取ID列表并执行查询:
public IList<Audit> AuditsByIDs(List<int> ids)
{
return _db.Audits
.Include(p => p.User)
.Where(p => ids.Any(i => i == p.Id)).ToList();
}
It works for a small number of ids , but when that gets to hundreds I get the error: 它适用于少量的ID ,但当达到数百时,我得到错误:
Some part of your SQL statement is nested too deeply. SQL语句的某些部分嵌套得太深。 Rewrite the query or break it up into smaller queries. 重写查询或将其分解为较小的查询。
How do I get the query to return only then the ids passed in? 如何让查询只返回传入的ID ? I can not change the data base :( 我无法更改数据库:(
Use Contains
instead: 使用Contains
代替:
public IList<Audit> AuditsByIDs(List<int> ids)
{
return _db.Audits
.Include(p => p.User)
.Where(p => ids.Contains(p.Id)).ToList();
}
Which should be transformed into IN
within generated SQL query. 哪个应该在生成的SQL查询中转换为IN
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.