From 0d9b962dc7abbcfc6d548ceec2b3b7bb72bfcd2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enis=20G=C3=BCrkan?= Date: Tue, 18 Jan 2022 11:07:51 +0300 Subject: [PATCH] ToListWithNoLock added --- EnLock/EnExtention.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/EnLock/EnExtention.cs b/EnLock/EnExtention.cs index 5462589..5b39816 100644 --- a/EnLock/EnExtention.cs +++ b/EnLock/EnExtention.cs @@ -56,6 +56,21 @@ public static async Task> ToListWithNoLockAsync(this IQueryable qu } return result; } + public static List ToListWithNoLock(this IQueryable query) + { + List result = default; + using (var scope = new TransactionScope(TransactionScopeOption.Required, + new TransactionOptions() + { + IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted + }, + TransactionScopeAsyncFlowOption.Enabled)) + { + result = query.ToList(); + scope.Complete(); + } + return result; + } public static async Task ToFirstOrDefaultWithNoLockAsync(this IQueryable query, CancellationToken cancellationToken = default) { T result = default;