C# System.Data.Services.Client.DataServiceContext超时属性不工作
我遇到一个问题,查询在检索结果之前超时。我使用的是实体框架v。6.0. 设置context.Timeout属性似乎没有任何影响 这是类声明和构造函数,所以您知道我在处理什么。它是从Reference.cs生成的代码:C# System.Data.Services.Client.DataServiceContext超时属性不工作,c#,entity-framework,C#,Entity Framework,我遇到一个问题,查询在检索结果之前超时。我使用的是实体框架v。6.0. 设置context.Timeout属性似乎没有任何影响 这是类声明和构造函数,所以您知道我在处理什么。它是从Reference.cs生成的代码: public partial class PSIDevEntities : global::System.Data.Services.Client.DataServiceContext { /// <summary> /// Initializ
public partial class PSIDevEntities : global::System.Data.Services.Client.DataServiceContext
{
/// <summary>
/// Initialize a new PSIDevEntities object.
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Services.Design", "1.0.0")]
public PSIDevEntities(global::System.Uri serviceRoot) :
base(serviceRoot, global::System.Data.Services.Common.DataServiceProtocolVersion.V3)
{
this.ResolveName = new global::System.Func<global::System.Type, string>(this.ResolveNameFromType);
this.ResolveType = new global::System.Func<string, global::System.Type>(this.ResolveTypeFromName);
this.OnContextCreated();
this.Format.LoadServiceModel = GeneratedEdmModel.GetInstance;
}
在某些地方,默认超时时间为30秒。我需要做什么来增加此查询的超时时间?答案是修改数据服务中自动生成的代码。哎呀!但它是有效的。更改数据服务的命令超时。在DbContext的构造函数中输入以下两行:
var objectContext = (this as IObjectContextAdapter).ObjectContext;
objectContext.CommandTimeout = 120; // Or any required timeout
因此,对于我的修复,我的构造函数现在如下所示:
public partial class PSIDevEntities : DbContext
{
public PSIDevEntities()
: base("name=PSIDevEntities")
{
base.Configuration.ProxyCreationEnabled = false;
var objectContext = (this as IObjectContextAdapter).ObjectContext;
objectContext.CommandTimeout = 120;
}
...
这真的有那么难吗?一定是我忽略了一些简单的事情。你收到的确切错误是什么?文档说这是HTTP超时,但您可能会收到来自SQL查询的错误。。。
public partial class PSIDevEntities : DbContext
{
public PSIDevEntities()
: base("name=PSIDevEntities")
{
base.Configuration.ProxyCreationEnabled = false;
var objectContext = (this as IObjectContextAdapter).ObjectContext;
objectContext.CommandTimeout = 120;
}
...