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;
    }
}

      

+3
c # sql entity-framework entity-framework-6


source to share


No one has answered this question yet

Check out similar questions:

1762
How to import SQL file using command line in MySQL?
783
Entity Framework vs LINQ to SQL
758
Entity Framework 5 Record Update
756
Failed to check for one or more objects. For more information, see "EntityValidationErrors Property".
630
Fastest way to insert into Entity framework
515
How can I get the ID of the inserted entity in the Entity framework?
461
How do I view the SQL generated by the Entity Framework?
401
Entity Framework Service Provider not found for ADO.NET Provider with invariant name 'System.Data.SqlClient'
392
Failed to load Entity Framework provider type?
289
Organization structure timeouts



All Articles
Loading...
X
Show
Funny
Dev
Pics