Open emumanu opened 9 years ago
Thanks for the suggestion and sample code!
Would you be able to give a little bit more details of the situation in which this would be required? If I knew more about the context, I might be able to suggest alternatives to manually re-creating the DbContext.
I'm importing a feed with 800000 products, generating a lot of updates and some inserts. Even I use AutoDetectChangesEnabled wisely to avoid calling DetectChanges several times, the memory consumption is too high (and double because I'm using a snapshot to detect changes), so I decided to split the task in several batches.
I also need something like this behavior. I'm updating ~500K records and I need to break it down into batches. Currently, if I call SaveChanges periodically (e.g., every 1000 records) I get the "cannot call SaveChanges more than once" error. Currently, what is the best way to handle this? Use ForceCreateNew? Thanks.
Hello,
thank you very much for the DbContextScope!. I was looking for something like this to properly handling my DbContexts.
The only thing I'm missing at the moment is the ability to recreate a particular DbContext, because when I'm making a lot of inserts, the change tracker has to keep track of a lot of entities and I get better performance recreating the context.
So, I have added this functionality in the DbContextCollection class (and in the IDbContextCollection interface):
I hope you find it useful and include it in your code.