Get Entity Framework 6 use NOLOCK in its underneath SELECT statements

后端 未结 4 681
星月不相逢
星月不相逢 2020-12-24 01:28

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

4条回答
  •  别那么骄傲
    2020-12-24 01:50

    You can use a workaround that don't use transaction scopes for each query. If you run the code below, ef will use the same transaction isolation level for the same Server Process ID. Since Server Process ID does not change in same request, only one call for each request is sufficient. This also works in EF Core.

    this.Database.ExecuteSqlCommand("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;");
    

提交回复
热议问题