【问题标题】:how do I set the command time out in the new ormlite api如何在新的 ormlite api 中设置命令超时
【发布时间】:2013-08-23 17:22:51
【问题描述】:

我升级到了新版本的 ormlite 并正在更新我的代码,但现在我看不到在哪里可以设置命令超时,因为所有事情都已关闭 idbconnection。

【问题讨论】:

标签: c# ormlite-servicestack


【解决方案1】:

正如我在另一个线程中发布的那样,我创建了一个扩展方法来处理这种情况并仍然保留了不错的 API:

public static partial class IDbConnectionExtensionMethods
{
    public static List<T> Query<T>(this IDbConnection self, string sql, TimeSpan commandTimeout)
    {
        List<T> results = null;
        self.Exec((dbCmd) =>
            {
                dbCmd.CommandTimeout = (int)commandTimeout.TotalSeconds;
                dbCmd.CommandText = sql;
                using (var reader = dbCmd.ExecuteReader())
                {
                    results = reader.ConvertToList<T>();
                }
            });

        return results;
    }   // eo Query<T>
}   // eo class IDbConnectionExtensionMethods

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-17
    • 2014-08-13
    • 1970-01-01
    • 2016-12-27
    • 2012-01-16
    • 1970-01-01
    • 1970-01-01
    • 2019-09-20
    相关资源
    最近更新 更多