实体框架 - 将异常结果保存到数据库 [英] Entity Framework - Saving results to the database asyncronously
问题描述
我观察到在执行了Web服务功能后,如果在实体数据库模型对象上没有调用SaveChanges,任何挂起的数据库更改都将被滚动背部。
我可以异步地将我的更改保存到数据库,我该怎么做?
原则上,您可以使用.NET中任何异步方法用于此目的。如果你可以使用.NET 4.5,那么建议你看看async / await方法,因为它们很容易使用。实体框架不支持async /等待从框,但您可以添加您的简单包装器使用 TaskCompletionSource 类。
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.
这篇关于实体框架 - 将异常结果保存到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!