I have an entity framework query that, when converted to SQL returns within a second, but when ran through entity framework times out after an hour (!) I tracked it down to the fact that, before executing the actual query, entity framework executes:
set arithabort off
I'm looking for either a way to configure EF not to do this, or for a way to override it.
I have tried the following:
public partial class MyContext : DbContext
{
public MyContext () : base("name=MyContext ")
{
Context.Database.ExecuteSqlCommand("set arithabort on");
}
public DbContext Context
{
get { return this; }
}
}
But this executes just once in the beginning, and gets overridden whenever another query is executed.
Thanks to @fiddler, adding an interceptor worked. Feels a bit hackish, but it certainly worked.
public partial class IfcContext : DbContext, IIfcContext
{
public MyContext() : base("name=MyContext")
{
///used to set ArithAbort to on before each query
DbInterception.Add(new Interceptor());
}
public DbContext Context
{
get { return this; }
}
}
public class Interceptor : IDbCommandInterceptor
{
public void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
{
command.CommandText = "SET ARITHABORT ON; " + command.CommandText;
}
public void NonQueryExecuting(DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
{
}
public void NonQueryExecuted(DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
{
}
public void ReaderExecuted(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
{
}
public void ScalarExecuting(DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
{
}
public void ScalarExecuted(DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
{
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With