开发者

LINQ to EF - Why is this query pulling back all the data THEN counting?

开发者 https://www.devze.com 2023-01-19 13:10 出处:网络
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?

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号