Reputation: 380
I want to iterate through a set of object and make changes and then commit those changes in groups because the amount of data could be very large. When i do this i am getting an ObjectDisposedException. Any suggestions for how to better handle this?
using (ITransaction tx = Session.BeginTransaction())
{
for (int i = 0; i < 100; i++)
{
//DO Something
if (i % 10 == 0)
{
tx.Commit();
}
}
}
Upvotes: 2
Views: 2127
Reputation: 13381
You are committing the transaction within a loop, meaning you are trying to commit one open transaction multiple times. This is not possible by design. One transaction can only be committed once.
So your two options are, have one transaction surrounding the loop
or one transaction per loop. Of course you can still batch your changes every x number of objects, but per batch you'll have to open a new transaction and commit the changes, then open another one etc...
Upvotes: 3