Reputation: 1493
I am having an issue where a query times out prior to retrieving results. I am using Entity Framework v. 6.0. Setting the context.Timeout property doesn't seem to have any affect.
Here is the class declaration and constructor so you know what I'm dealing with. It's generated code from the Reference.cs:
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;
}
I have tried setting the Timeout to a high number. However, the query times out after 30 seconds.
var context = new PSIDevEntities(URI);
context.Timeout = 120000;
var result = from p in context.vwPacings
where p.InactiveDateTime == null
orderby p.ProgramTitle
select p;
// timeout occurs here after 30 seconds
retList = result.ToList();
Somewhere, there is a default timeout of 30 seconds. What do I need to do to increase the timeout for this query?
Upvotes: 2
Views: 593
Reputation: 1493
The answer is to modify the auto-generated code in the data service. Yikes! But it works. To change the command timeout for the dataservice. Enter these two lines into the constructor of the DbContext:
var objectContext = (this as IObjectContextAdapter).ObjectContext;
objectContext.CommandTimeout = 120; // Or any required timeout
So for my fix my constructor now looks like this:
public partial class PSIDevEntities : DbContext
{
public PSIDevEntities()
: base("name=PSIDevEntities")
{
base.Configuration.ProxyCreationEnabled = false;
var objectContext = (this as IObjectContextAdapter).ObjectContext;
objectContext.CommandTimeout = 120;
}
...
Upvotes: 2