?
Solved

Linq Performance about large table

Posted on 2008-10-24
2
Medium Priority
?
704 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
[X]
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
2 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

764 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