Use of TransactionScope with read uncommitted - is with (nolock) in SQL necessary?

前端 未结 2 1897
旧巷少年郎
旧巷少年郎 2021-02-20 11:52

I am using FluentNHibernate, and I have a list of records, mapped to an SQL Server 2008 view. Dirty reads are OK with me, not locking the tables is a priority.

The SQL Q

2条回答
  •  庸人自扰
    2021-02-20 12:35

    I'm not sure why, but the TransactionScope code did not work for me.

    I used this code. Starting a new session below makes sure that you don't have an existing transaction already. (There are other ways to do it of course)

            using (var session = _session.SessionFactory.OpenSession())
            using (var txn = session.BeginTransaction(IsolationLevel.ReadUncommitted))
            {
                // bunch of select statements.
            }
    

    In the NHibernate Profiler I could see this:

    begin transaction with isolation level ReadUncommitted
    

提交回复
热议问题