views:

23

answers:

1

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 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();
+5  A: 

To fix this, you should change your Func<T1, TResult> to an Expression<Func<T1, TResult>>. See this other question for explanation why

Sander Rijken
Excellent, many thanks for the quick reply and the link!
Jason Hyland