0

I am using EF for access MS SQL data with help LINQ. How can I get current isolation level ? For example this code:

var level = 
Database.Connection.UnderlyingTransaction.IsolationLevel.ToString();

give me error - System.NullReferenceException: Object reference not set to an instance of an object.

As I understand - UnderlyingTransaction is null because I don't use any transactions in my LINQ code.

Aleksandr Zolotov
  • 1,078
  • 3
  • 19
  • 32

1 Answers1

0

I cannot find how to get current isolation level with EF properties or methods , so we can use custom SQL query for that, for example like this:

public class UserOptionsMsSql
{
    [Column("Set Option")]
    public string SetOption { get; set; }

    public string Value { get; set; }
}

var resultsList = 
service.GetDataContext().Database.SqlQuery<UserOptionsMsSql>
("DBCC USEROPTIONS;").ToList();

var resultLevel =  resultsList[11] == null ? "unknown":resultsList[11].Value ;

Of course we can use any other custom SQL scripts ...

Aleksandr Zolotov
  • 1,078
  • 3
  • 19
  • 32