I have a web-service which gets called every few seconds, which does a bunch of things and then performs a bulk insert which currently takes half a second on average to call SaveChanges(). I’d like to save all the changes asynchronously because then I can call my web-service multiple times per second and just buffer any database changes to be saved by a quartz timer, which should lead to better performance.
I’ve observed that after a web-service function executes, if the “SaveChanges” was not called on the entity database model object, any pending database changes will be rolled back.
Is it possible for me to asynchronously save my changes to the database and how would I go about doing it?
In principle, you could use any of asynchronous approaches available in .NET for such purpose. If you could use .NET 4.5 then I’d suggest you to take a look at async/await methods, because they’re quite easy to use. Entity framework doesn’t support async/await from the box, but you could add your simple wrappers by using TaskCompletionSource class.