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

New Post: EF6, Enumerable.Contains and auto compilation

$
0
0
There are no plans to enable auto-compiled query on queries with Enumerable.Contains in EF6.

In general enabling auto-compiled query for those would be easy but two queries that differ only on the contents of the collection passed to Enumerable.Contains would still need to resolve to different cache entries because the two of them would need to translate to different SQL, e.g.:

var list = new [] {1,2,3,4};
var query = db.Products.Where(p => list.Contains(p.CategoryId);
// query translates to something like SELECT * FROM Products WHERE CategoryId IN (1,2,3,4)
list = new [] {5,6,7};
// now query translates to something like SELECT * FROM Products WHERE CategoryId IN (5,6,7)

Auto-compiled query would still be able to help if you need to execute the same query with the same collection but varying some other parameter.

One way we think we can enable auto-compiled queries to work in more scenarios with Enumerable.Contains is by adding the capability to EF to take advantage of Table Valued Parameters when the target database supports them. That should enable us to produce the exact same SQL for the two queries above and just pass different parameters each time.

Diego

Viewing all articles
Browse latest Browse all 10318

Trending Articles



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