如何在 ASP.NET MVC 中处理请求式数据库事务?
我正在使用 SubSonic 3.0 (SimpleRepository) 来处理 ASP.NET MVC 1.0 应用程序中的数据库访问。
如果能够为每个 Web 请求处理一个事务,如果一切顺利则提交并在出现异常时回滚,这将是很好的做法。这可能吗?如果是这样,怎么办?
我知道这个话题已经讨论过很多次了,但我就是找不到满意的答案。我已经构建了自己的解决方案(在控制器中创建 TransactionScope,然后在 OnActionExecuted 中提交/回滚),但事实证明它非常不可靠。
I'm using SubSonic 3.0 (SimpleRepository) to handle database access in my ASP.NET MVC 1.0 application.
It would be nice to handle a transaction for every web request, committing if everything went smooth and rolling back in case of exception. Is this possible? If so, how?
I know this topic has been discussed many times, but I just couldn't find a satisfactory answer. I have built my own solution (create a TransactionScope in the controller, then commit/rollback in OnActionExecuted), but it turns out to be very unreliable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
链接 http://ayende.com/Blog/archive/2011/04/12/refactoring-toward-frictionless-amp-odorless-code-what-about-transactions.aspx 适用于 NHibernate 但我很确定你也可以使用它。基本上它谈论创建自定义操作过滤器。确实,它是在行动范围内而不是在请求范围内进行的。
The link http://ayende.com/Blog/archive/2011/04/12/refactoring-toward-frictionless-amp-odorless-code-what-about-transactions.aspx applies to NHibernate but i am quite sure you can use it as well. Basically it talks about creating custom action filter . It is also true that it does it action-wide not request wide.