How does the Take() method work?

.net c# entity-framework linq linq-to-entities

Question

I'm using my web app to query a relatively huge table, and I only want to return N number of rows from the table.

I've reviewed the MSDN material, but I can't find any references to whetherTake() firstly retrieves every record from the database, or if it functions similarly to SQL Server'sTOP .

If, I'm concernedTake() will it operate as intended and only retrieve the N number of records directly, or will it pull all data and get the top N number of records?

1
8
10/21/2015 10:08:21 PM

Accepted Answer

ZZZ_tmp
11
2/22/2017 12:12:54 PM

Popular Answer

It makes the best effort it can.

Given that you appear to be using SQL Server, whose engine is aware of SQL Server's existence,TOP It'll employ that. Additionally, MS Access would make use of this.

It would utilize PostgreSQL, MySQL, or SQL Lite if you were usingLIMIT .

The potential usage of"fetch first " + n + " rows only" regular DB2 and SQL 2008 format) or"select first " + n + "from" (Informix fashion)"select * from (" + restOfQuery + ") where rownum <= " + n on Oracle or whichever particular database was required.

And if someone created a database engine that could not under any circumstances support such limits, it might in fact close the result stream once it had taken what it required.

In each instance, it makes the best effort possible given the circumstances.

In addition, it applies the same methodology to a value of1 for First() with its variations and a value of2 for Single() including its variations (since you need to try to take at least 2 rows to test that there is only 1 to take).



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow