Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Linq Performance about large table

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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Suggested Solutions

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…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

829 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