Solved

Linq Performance about large table

Posted on 2008-10-24
2
695 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

685 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