ServiceStack OrmLite 命令超时 [英] ServiceStack OrmLite Command Timeout

查看:39
本文介绍了ServiceStack OrmLite 命令超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 IDbConnection.ExecuteSql 时如何设置命令超时?

When using IDbConnection.ExecuteSql how do I set the Command Timeout?

IDbConnection db = ConnectionFactory.OpenDbConnection();
db.ExecuteSql("...");

如果我使用 IDbCommand.ExecuteSql(见下文)方法,我可以设置命令超时,但我会收到一堆关于已弃用方法的警告.

If I use the IDbCommand.ExecuteSql ( See below ) method I can set the Command Timeout, but I get a bunch of warnings about deprecated methods.

IDbCommand comm = db.CreateCommand()
comm.CommandTimeout = 240;                    
comm.ExecuteSql("...");

推荐答案

随着最近的变化 OrmLite 不再直接提供围绕 IDbCommand 对象的 API(现在这些 API 在最新的版本).

With the most recent change OrmLite no longer provides APIs around the IDbCommand object directly (which have now all been made internal in the latest version).

但由于 OrmLite 只是 ADO.NET 底层的扩展方法 IDbConnectionIDbCommand 接口,您可以在需要时轻松绕过 OrmLite 的扩展方法,直接使用它们,例如:

But since OrmLite is only extension methods over ADO.NET's underlying IDbConnection and IDbCommand interfaces, you can easily by-pass OrmLite's extension methods when you need to and just use them directly, e.g:

IDbConnection db = ConnectionFactory.OpenDbConnection();
IDbCommand cmd = db.CreateCommand();
cmd.CommandTimeout = 240;  
cmd.CommandText = "...";
cmd.ExecuteNonQuery();

或者,您可以使用以下命令设置全局 CommandTimeout:

Alternatively you can set a global CommandTimeout with:

OrmLiteConfig.CommandTimeout = 240;

这篇关于ServiceStack OrmLite 命令超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆