Solved

Linq Performance about large table

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

Accepted Solution

by:
Fernando Soto earned 125 total points
Comment Utility
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
Comment Utility
I was afraid of your answer, and it's very a pity that LINQ works like this.
Thank you
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How do I get the unique ID after insert? 87 87
Jquery oncheck to update SPAN 31 55
GridDataView 6 44
Need to Modify a Script I found 5 75
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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now