@@ -86,7 +86,7 @@ public static async Task<T> ToFirstOrDefaultWithNoLockAsync<T>(this IQueryable<T
86
86
}
87
87
return result ;
88
88
}
89
- public static async Task < T > ToFirstWithNoLockAsync < T > ( this IQueryable < T > query , CancellationToken cancellationToken = default )
89
+ public static async Task < T > ToFirstWithNoLockAsync < T > ( this IQueryable < T > query , Expression < Func < T , bool > > predicate , CancellationToken cancellationToken = default )
90
90
{
91
91
T result = default ;
92
92
using ( var scope = new TransactionScope ( TransactionScopeOption . Required ,
@@ -95,6 +95,21 @@ public static async Task<T> ToFirstWithNoLockAsync<T>(this IQueryable<T> query,
95
95
IsolationLevel = System . Transactions . IsolationLevel . ReadUncommitted
96
96
} ,
97
97
TransactionScopeAsyncFlowOption . Enabled ) )
98
+ {
99
+ result = await query . FirstAsync ( predicate , cancellationToken ) ;
100
+ scope . Complete ( ) ;
101
+ }
102
+ return result ;
103
+ }
104
+ public static async Task < T > ToFirstWithNoLockAsync < T > ( this IQueryable < T > query , CancellationToken cancellationToken = default )
105
+ {
106
+ T result = default ;
107
+ using ( var scope = new TransactionScope ( TransactionScopeOption . Required ,
108
+ new TransactionOptions ( )
109
+ {
110
+ IsolationLevel = System . Transactions . IsolationLevel . ReadUncommitted
111
+ } ,
112
+ TransactionScopeAsyncFlowOption . Enabled ) )
98
113
{
99
114
result = await query . FirstAsync ( cancellationToken ) ;
100
115
scope . Complete ( ) ;
@@ -116,5 +131,21 @@ public static async Task<T> ToSingleWithNoLockAsync<T>(this IQueryable<T> query,
116
131
}
117
132
return result ;
118
133
}
134
+
135
+ public static async Task < T > ToSingleWithNoLockAsync < T > ( this IQueryable < T > query , Expression < Func < T , bool > > predicate , CancellationToken cancellationToken = default )
136
+ {
137
+ T result = default ;
138
+ using ( var scope = new TransactionScope ( TransactionScopeOption . Required ,
139
+ new TransactionOptions ( )
140
+ {
141
+ IsolationLevel = System . Transactions . IsolationLevel . ReadUncommitted
142
+ } ,
143
+ TransactionScopeAsyncFlowOption . Enabled ) )
144
+ {
145
+ result = await query . SingleAsync ( predicate , cancellationToken ) ;
146
+ scope . Complete ( ) ;
147
+ }
148
+ return result ;
149
+ }
119
150
}
120
151
}
0 commit comments