Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does OrderBy in LINQ work (behind the scenes)?

I already know that LINQ works by evaluating expressions and iterating one by one through them (kind of like a pipeline), however there are certain operations like OrderBy that need to be buffered since sorting needs to analyze all the data at once to do the sort.

I am interested in knowing how this data is buffered in LINQ behind the scenes.

If anyone can point me to an article or explanation I would appreciate it.

Thanks

like image 551
aattia Avatar asked Nov 06 '22 20:11

aattia


1 Answers

It is up to the LINQ provider to implement. Some providers (e.g., LINQ to SQL, LINQ to Entities) will transliterate to a SQL OrderBy. Others (LINQ to Objects) will sort on the client. All LINQ really does itself is call a method named OrderBy or OrderByDesc.

like image 141
Craig Stuntz Avatar answered Nov 16 '22 16:11

Craig Stuntz