Skip to content

Commit ce4c1ca

Browse files
committed
ToSingleWithNoLockAsync predicate added
1 parent 6c236cc commit ce4c1ca

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

EnLock/EnExtention.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static async Task<T> ToFirstOrDefaultWithNoLockAsync<T>(this IQueryable<T
8686
}
8787
return result;
8888
}
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)
9090
{
9191
T result = default;
9292
using (var scope = new TransactionScope(TransactionScopeOption.Required,
@@ -95,6 +95,21 @@ public static async Task<T> ToFirstWithNoLockAsync<T>(this IQueryable<T> query,
9595
IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted
9696
},
9797
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))
98113
{
99114
result = await query.FirstAsync(cancellationToken);
100115
scope.Complete();
@@ -116,5 +131,21 @@ public static async Task<T> ToSingleWithNoLockAsync<T>(this IQueryable<T> query,
116131
}
117132
return result;
118133
}
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+
}
119150
}
120151
}

EnLock/EnLock.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5-
<Nullable>enable</Nullable>
5+
<Nullable>disable</Nullable>
66
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
77
<PackageId>ENLOCK</PackageId>
88
<Title>ENLOCK</Title>
@@ -18,7 +18,7 @@
1818
</PropertyGroup>
1919

2020
<ItemGroup>
21-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.0.1" />
21+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.6" />
2222
</ItemGroup>
2323

2424
</Project>

0 commit comments

Comments
 (0)