Using EF 3.5 - why does the first query appear to generate a SELECT COUNT(*)... whilst the second appears to pull back all the data before performing the where?
var model = new SageEntities();
Func<nltranm, bool> marked_as_extracted =
n => n.history_ref != null;
// SELECT COUNT(*) ?
var开发者_StackOverflow records_marked_as_extracted_quick = model.nltranm.Where(n => n.history_ref != null).Count();
// Pull back all data and the count ...
var records_marked_as_extracted_slow = model.nltranm.Where(marked_as_extracted).Count();
To fix this, you should change your Func<T1, TResult>
to an Expression<Func<T1, TResult>>
.
See this other question for explanation why
精彩评论