controlling ArithAbort in EF4

有些话、适合烂在心里 提交于 2019-11-29 15:18:19

问题


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 ?



来源:https://stackoverflow.com/questions/6344992/controlling-arithabort-in-ef4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!