【问题标题】:How to set command timeout for entity objectcontext如何为实体对象上下文设置命令超时
【发布时间】:2018-04-24 12:00:08
【问题描述】:

我有一个存储库文件,我们在其中创建了实体类型而不是 ObjectContext 类类型的对象上下文

public class ShopRepository : GenericRepository<tbl_Shop>
{
        // Entity Framework context to the database
        private DBEntities _contextObject;

        public ShopRepository(DBEntities context)
            : base(context)
        {
            this._contextObject = context;
        }
}

我需要设置命令超时属性。 谁能帮帮我

【问题讨论】:

    标签: c# entity-framework dbcontext command-timeout


    【解决方案1】:

    您可以通过ObjectContextCommandTimeout 属性访问DbContext 命令超时,如下所示:

    ((IObjectContextAdapter)context).ObjectContext.CommandTimeout
    

    因此,如果您想在 ShopRepository ctor 中设置它,请执行以下操作:

    public ShopRepository(DBEntities context)
            : base(context)
    {
         ((IObjectContextAdapter)context).ObjectContext.CommandTimeout = your_value_here;
         this._contextObject = context;
    }
    

    【讨论】:

      猜你喜欢
      • 2012-07-29
      • 2012-05-17
      • 1970-01-01
      • 2013-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      相关资源
      最近更新 更多