Is the complete list returned first and then filtered when using linq for sql to filter data from a database or just a filtered list?

This is probably a very simple question that I am working on in an MVC project. Here is an example of what I'm talking about.

I have an rdml file associated with a database with a Users table that has 500,000 rows. But I only want to find Users who were introduced on 5/7/2010. So let me say that I do this in my UserRepository:

from u to db.GetUsers (), where u.CreatedDate = "5/7/2010" select u
(by doing this from memory, so don't kill me if my syntax doesn't work a bit, this is the concept I'm looking for)

Does this statement first return all 500,000 rows and then filter it or only returns a filtered list?

+3
source share
4 answers

It filters in the database since you are building your expression on top of ITablereturning the data source IQueryable<T>.

+3
source

Linq to SQL translates your query into SQL before sending it to the database, so only the filtered list is returned.

+1
source

, SQL .

: , .

, .

+1

, , , - , LinqToSql. LinqToSql - , . , , .

DataContext "Log", , . HttpModule, DataContext Log ( ) . , SQL, , . .

Side note. I do not want to be negative about the SQL that LinqToSql creates as it is very good and efficient almost every time. Another good side effect of query monitoring is that you can show your friends who are hard ADO.NET - Proc stored people how effective LinqToSql really is.

0
source

Source: https://habr.com/ru/post/1744950/


All Articles