DbContext和DbDomainService - 增加超时

时间:2013-07-01 10:04:36

标签: entity-framework wcf-ria-services

我正在尝试访问ObjectContext,以便能够使用WCF RIA / EF5增加CommandTimeout

protected override MyEntities CreateDbContext()
{
    var dbContext = base.CreateDbContext();

    // returns a null ref
    // Get the ObjectContext related to this DbContext
    var objectContext = (this as IObjectContextAdapter).ObjectContext;            

    objectContext.CommandTimeout = 120;
    return dbContext;
}

这不起作用。

目前,EF超时为30秒。

1 个答案:

答案 0 :(得分:0)

我可能已经得到了:

 protected override MyEntities CreateDbContext()
        {
            var dbContext = base.CreateDbContext();

            // Get the ObjectContext related to this DbContext
            var objectContext = (dbContext as IObjectContextAdapter).ObjectContext;

            // Sets the command timeout for all the commands
            objectContext.CommandTimeout = 240;

            return dbContext;
        }