如何在Entity Framework 6 DbContext.Database.BeginTransaction中配置事务超时?

编程入门 行业动态 更新时间:2024-10-24 12:22:06
本文介绍了如何在Entity Framework 6 DbContext.Database.BeginTransaction中配置事务超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

使用代码如

using(var tran = Ctxt.Database.BeginTransaction()){

如何设置事务超时的值?

解决方案

我的建议是使用 Database.CommandTimeout :

var timeout = 60; //或者你需要的任何值 Ctxt.Database.CommandTimeout = timeout; 使用(var tran = Ctxt.Database.BeginTransaction()) { //做东西} //如果你是将要配置上下文 Ctxt.Database.CommandTimeout = null; //设置默认超时

当然,你可以很好地将它包装在一些类中。 >

Using code like

using (var tran = Ctxt.Database.BeginTransaction()) {

How can I set a value for the transaction timeout ?

解决方案

My suggestion would be to use Database.CommandTimeout:

var timeout = 60; //or whatever value you need Ctxt.Database.CommandTimeout = timeout; using (var tran = Ctxt.Database.BeginTransaction()) { //do stuff } //this line can be skipped if you're about to dispose context Ctxt.Database.CommandTimeout = null; //setting back default timeout

Of course, you can nicely wrap it in some class.

更多推荐

如何在Entity Framework 6 DbContext.Database.BeginTransaction中配置事务超时?

本文发布于:2023-11-14 00:52:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1585771.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:事务   如何在   Entity   DbContext   Framework

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!