Hello.<br /><br />This is very strange behavior. I have three entities, and a simple query:<br />var a = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };<br />using (var context = new Sales_ReleaseEntities())<br />{<br /> context.TreasuryDocumentDetails.Where(x => a.Contains(x.TreasuryDocument.Customer.PersonID)).ToList();<br />}<br /><br />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. <br />A complete working project is attached, which includes both models, the database creation script, and the query results.<br /><br />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!<br /><br />How can we avoid this problem?
↧