controlling ArithAbort in EF4

2019-02-07 11:24发布

问题:

We are having some performance issues with our EF4 MVC solution. We've been able to track it down to ArithAbort getting set to off before all connections to the database, and now we are trying to force it to stay as 'ON'.

We've looked at: How do you control the "SET" statements emitted by Linq to SQL

But it seems like EF4 is resetting the connection before each query, so that won't work.

So far we've tried "set ArithAbort on" before a given query, with no luck. We've also tried going the long way and making a new connection where we set it, but still no luck.

So, anyone have a clue as to how we can get it to set it before making any linq queries against the database?

Changing database settings isn't an option.

Edit: Per Andiihs suggestion I tried out the wrapper solution and added in the following lines of code to the EFCachingCommand class

    protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
    {
        if (this.WrappedCommand.CommandType == System.Data.CommandType.Text)
        {
            this.WrappedCommand.CommandText = "set arithabort on; " + this.WrappedCommand.CommandText;
        }

This essentially ensures that any Linq-sql calls get prefixed with the right set statement.

I also had to add:

    DbFunctionCommandTree functionTree = commandTree as DbFunctionCommandTree;
    if (functionTree != null)
    {
        this.IsModification = true;
        return;
    }

To the GetAffectedEntitySets function in the EFCachingCommandDefinition, in order to get it to work properly with stored procedure calls.

回答1:

EF provides the ability to insert a Wrapping Provider between Entity Connection and SQL.Data.Client - see http://code.msdn.microsoft.com/EFProviderWrappers and http://blogs.msdn.com/b/jkowalski/archive/2009/06/11/tracing-and-caching-in-entity-framework-available-on-msdn-code-gallery.aspx

Now I admit this is more of a clue than an answer - but perhaps you can insert the relevant set at this point ?