本文介绍了如何在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 timeoutOf course, you can nicely wrap it in some class.
更多推荐
如何在Entity Framework 6 DbContext.Database.BeginTransaction中配置事务超时?
发布评论