Quantcast
Channel: Entity Framework
Viewing all articles
Browse latest Browse all 10318

Edited Issue: huge query generation in Code-First by calling List.Contains in where Clause [655]

$
0
0
Hello.

This is very strange behavior. I have three entities, and a simple query:
var a = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
using (var context = new Sales_ReleaseEntities())
{
context.TreasuryDocumentDetails.Where(x => a.Contains(x.TreasuryDocument.Customer.PersonID)).ToList();
}

This query generates a normal query, when used with an Edmx model. However, with the code-first approach it generates a large query which joins to Customers table 19 times and uses each on the joins to check for a single value in the int[] array.
A complete working project is attached, which includes both models, the database creation script, and the query results.

While this query is not huge by itself, we have situations in the actual project in which the generated query is several thousand lines long. We even have a query that fails to translate to sql in the first step!

How can we avoid this problem?

Viewing all articles
Browse latest Browse all 10318

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>