开发者

is my linq query pulling just what it needs or everything?

开发者 https://www.devze.com 2023-02-12 07:57 出处:网络
I do something like this: var src = dbContext.Set<Person>().Where(o => o.LastName.StartsWith(search));

I do something like this:

var src = dbContext.Set<Person>().Where(o => o.LastName.StartsWith(search));
var page = src.OrderBy(u => u.Id).Skip((page - 1) * pageSize).Take(pageSize);
var count = src.Count();

is ef pulling from the database everything and after does the query or not ? how do I know this? what are the way开发者_如何学JAVAs finding out this?

(using ef4 ctp5 code first)


Try downloading LinqPad, it will show you the SQL that gets executed so you can see exactly what's happening.

Here's a Linq query and the results:

is my linq query pulling just what it needs or everything?

Here's the same Linq query along with the SQL that gets executed:

is my linq query pulling just what it needs or everything?

It's a very good tool for writing and optimising Linq to EF and Linq to SQL queries. It's also great for writing and testing .Net code snippets.

This tool has saved me so much time simply because you don't need to fire up the debugger! It's the most useful .Net tool that I've found in years.


None of the calls you are using is a To* operator (like ToList), so all method calls will be translated into SQL and executed in the database. However, the Count operator is immediately evaluated, you might should delay that assignment to the place you actually need the value. The other variables will be evaluated once iterated over.

0

精彩评论

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