score:21

Accepted answer

the iqueryable<dailyresult> dtable will attempt to load the entire query result into memory when enumerated... before any iterations of the foreach loop. it does not load one row during the iteration of the foreach loop. if you want that behavior, use datareader.

score:0

i would suggest using sql instead to modify this data.

score:1

use .asnotracking() - it tells dbentities not to cache retrieved rows

using (var conn = new dbentities() { commandtimeout = 600*100})
{
     var dtable = conn.dailyresults
                .asnotracking()      // <<<<<<<<<<<<<<
                .where(dr => dr.dailytransactiontypeid == 1);
     foreach (var dailyresult in dtable)
     {
        //math here, results stored in-memory, but this table is very small. 
        //at the very least compared to stuff i already have in memory. :)
     }
}

score:2

using datareader is a step backward unless there is a way to use it within linq. i thought we were trying to get away from ado.

the solution suggested above works, but it's truly ugly. here is my code:

int itake = 40000;
int iskip = 0;
int iloop;
ent.commandtimeout = 6000;
while (true)
{
  iloop = 0;
  iqueryable<viewclaimsbinfo> iinfo = (from q in ent.viewclaimsbinfo
                                       where q.workdate >= dtstart &&
                                         q.workdate <= dtend
                                       orderby q.workdate
                                       select q)
                                      .skip(iskip).take(itake);
  foreach (viewclaimsbinfo qinfo in iinfo)
  {
    iloop++;
    if (lstclerk.contains(qinfo.clerk.substring(0, 3)))
    {
          /// various processing....
    }
  }
  if (iloop < itake)
    break;
  iskip += itake;
}

you can see that i have to check for having run out of records because the foreach loop will end at 40,000 records. not good.

updated 6/10/2011: even this does not work. at 2,000,000 records or so, i get an out-of-memory exception. it is also excruciatingly slow. when i modified it to use oledb, it ran in about 15 seconds (as opposed to 10+ minutes) and didn't run out of memory. does anyone have a linq solution that works and runs quickly?

score:7

you call ~10gb smallish? you have a nice sense of humor!

you might consider loading rows in chunks, aka pagination.

conn.dailyresults.where(dr => dr.dailytransactiontypeid == 1).skip(x).take(y);

Related Query

More Query from same tag