Solved

Linq Performance about large table

Posted on 2008-10-24
2
692 Views
Last Modified: 2013-11-11
Hi,

Suppose i have a table MYTABLE with millions of records.
Suppose i use this code :

var result = from e in DC.MYTABLE
                    where ....
                     select e;
foreach( MYTABLE record in result )
{
}

In SQL server management studio, if i run the equivalent query, i will get a long long very long result set.
In LINQ, what am i supposed to understand when the foreach is executed ?

1/ All millions of records from MYTABLE are sent ONCE to my application and stored in memory ?

2/ OR at each FOREACH statement, only one record is sent at a time by SQL server to my application ?

What is the correct answer ?
(Because i cannot use the Take() linq statement, i must browse the recordset)

Thank you
0
Comment
Question by:mars
2 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 125 total points
ID: 22800244
Hi mars;

When the Linq query is executed in the foreach loop it first executes the query and gets all the records. The only way to brows the records is to use the Take and Skip methods.

The following link has tips that can help to make Performance better. Tip 9 talks about the Take and Skip methods.

10 Tips to Improve your LINQ to SQL Application Performance
http://www.sidarok.com/web/blog/content/2008/05/02/10-tips-to-improve-your-linq-to-sql-application-performance.html

Fernando
0
 

Author Comment

by:mars
ID: 22800373
I was afraid of your answer, and it's very a pity that LINQ works like this.
Thank you
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question