Search code examples
servicestackormlite-servicestack

ServiceStack.OrmLite nolock hint in SQL Server


I have been reviewing the ServiceStack.OrmLite.SqlServer library and it works very well but we were looking at the SQL generated and we wanted to add a nolock hint to our select statements but could not find a any documentation around this?

Current:

exec sp_executesql N'SELECT "GroupID", "Name", "ShortName", "GroupTypeID", "ParentGroupId" FROM "Group" WHERE "GroupID" = @GroupID',
                   N'@GroupID int', @GroupID = 5543

Would like:

exec sp_executesql N'SELECT "GroupID", "Name", "ShortName", "GroupTypeID", "ParentGroupId" FROM "Group" **WITH (NOLOCK)** WHERE "GroupID" = @GroupID',
                   N'@GroupID int', @GroupID = 5543

Any one know how to do this?


Solution

  • My preference is to wrap the database call in a system transaction, rather than trying to embed a SQL Server hint into the query.

    using (var db = dbFactory.OpenDbConnection())
    {
        using (var tran = db.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted))
        {
            return db.Select<Group>();
        }
    }