I am using Entity Framework 6 in an MVC 5 project. As you\'re aware of, SELECT queries in SQL Server perform faster and more efficient if we use WITH (NOL
I agree with what codeworx says in a way that Read Uncommitted can be dangerous. If you can live with dirty reads, go for it.
I found a way to make this work without changing anything in the current queries.
You need to create a DbCommandInterceptor like this:
public class IsolationLevelInterceptor : DbCommandInterceptor
{
private IsolationLevel _isolationLevel;
public IsolationLevelInterceptor(IsolationLevel level)
{
_isolationLevel = level;
}
//[ThreadStatic]
//private DbCommand _command;
public override void ReaderExecuting(DbCommand command, DbCommandInterceptionContext interceptionContext)
{
SetTransaction(command);
}
public override void ScalarExecuting(DbCommand command, DbCommandInterceptionContext
then at the cctor (static contructor of your dbcontext) just add the interceptor to the DbInfrastructure of entity framework collections.
DbInterception.Add(new IsolationLevelInterceptor());
this will for each command that EF sends to the store, wraps over a transaction with that Isolation Level.
In my case worked well, since we write data through an API where that data is not based on the readings from the database. (data can be corrupted because of the dirty reads) and so worked fine.