Entity Framework not honoring command timeout
I ran into an issue with an entity based api where third party developers mistakenly sent requests too large and caused the system to give up performance. I informed them to stop the practice, but I would like to limit requests to 1 minute and then just turn them off.
It looks like I should just set the command timeout in the constructor (shown below). When I test it with a long query, it executes the query exactly as it did before (3+ minutes), it doesn't seem to honor the command timeout at all.
Did I do something wrong? Doesn't that mean the command timeout will work? Is it isync, command timeout doesn't work with async? Any solutions or pointers would be greatly appreciated.
public class CustomContext : DbContext
{
public CustomContext(string connectionName)
: base(connectionName)
{
var objectContext = (this as IObjectContextAdapter).ObjectContext;
objectContext.CommandTimeout = 60;
}
public CustomContext(EntityConnection connection)
: base(connection, contextOwnsConnection: false)
{
var objectContext = (this as IObjectContextAdapter).ObjectContext;
objectContext.CommandTimeout = 60;
}
}
source to share
No one has answered this question yet
Check out similar questions: