I have a EF6 query that takes a list of IDs and does a query:
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:
Some part of your SQL statement is nested too deeply. Rewrite the query or break it up into smaller queries.
How do I get the query to return only then the ids passed in? I can not change the data base :(
Use Contains
instead:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With