When I try to update many posts (~50000) using SubSonic 3.0.0.4 after about 25000 updates i get an exception, out of memory. (Windows7, VS10, SQLServer2008R2)
var myTable = new SubSonicRepository<MyObject>(new MyDB());
getDataFromALargeList
foreach(post in LargeList)
{
var myObject=GetMyObject(int myID)
myObject.property1=..
myObject.property2=..
myTable.Update(myObject);
}
private MyObject GetMyObject(int myID)
{
var myObject = new MyObject();
var tbl = new SubSonicRepository<MyObject>(new MyDB());
return tbl.Load(myObject, "ID", id) ? myObject : new MyObject();
}
Any ideas?
You will need to do your updates in batches if you really want to do this within your application code, because your post objects are exceeding the memory allocation limits of the .NET runtime.
Your code should count the total number of records that you need to process, and then select records for processing in batches of say 500, until done. This way, memory can be reclaimed by the garbage collector as your post objects pass out of scope (for each batch) and you progress through the processing of all the records.
Alternatively, this is probably one of those occasions where it is worth dropping down to raw SQL. If you do these updates often it could be well worth your time to write a procedure to do this inside the database.