Skip to content

Commit

Permalink
WITH(NOLOCK) positioned before the where clause if there is no alias …
Browse files Browse the repository at this point in the history
…for the table.
  • Loading branch information
AndreaPiovanelli committed Apr 11, 2024
1 parent 441c6da commit 9568293
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Orchard/Data/NoLockInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,13 @@ private string AddNoLockHints(string query, IEnumerable<string> tableNames) {
if (tableIndex == fromIndex + 1
|| parts[tableIndex - 1].Equals(",")) {

parts.Insert(tableIndex + 2, "WITH(NOLOCK)");
if (parts[tableIndex+1].Equals("where", StringComparison.OrdinalIgnoreCase)) {
// There is no alias in the query, so we add "WITH(NOLOCK)" immediately after table name but before the "where" clause.
parts.Insert(tableIndex + 1, "WITH(NOLOCK)");
} else {
// We add "WITH(NOLOCK)" after the table alias
parts.Insert(tableIndex + 2, "WITH(NOLOCK)");
}
} else {
// probably doing a join, so edit the next "on" and make it
// "WITH (NOLOCK) on"
Expand Down

0 comments on commit 9568293

Please sign in to comment.