命令超时与实体框架4.1代码第一 [英] Command Timeout with Entity Framework 4.1 Code First

查看:109
本文介绍了命令超时与实体框架4.1代码第一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置DbContext的命令超时?

How can I set the command timeout of a DbContext?

推荐答案

我在另一个Google搜索后找到了这个解决方案。您可以通过将转换为IObjectContextAdapter来访问DbContext的ObjectContext。

I found this solution after another Google search. You can access the ObjectContext for a DbContext by casting this to an IObjectContextAdapter.

http://social.msdn.microsoft.com/Forums/en-ZA/ adodotnetentityframework / thread / 6fe91a64-0208-4ab8-8667-d061af340994

public class MyContext : DbContext
{
    public MyContext ()
        : base(ContextHelper.CreateConnection("my connection string"), true)
    {
        ((IObjectContextAdapter)this).ObjectContext.CommandTimeout = 300;
    }
}

这篇关于命令超时与实体框架4.1代码第一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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