Skip to content

Commit 83343fa

Browse files
Enis GürkanEnis Gürkan
authored andcommitted
Add project files.
1 parent a9e8c4e commit 83343fa

File tree

3 files changed

+140
-0
lines changed

3 files changed

+140
-0
lines changed

EnLock.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31912.275
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EnLock", "EnLock\EnLock.csproj", "{2AC7594B-6D50-447C-908E-AE74172E288C}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{2AC7594B-6D50-447C-908E-AE74172E288C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{2AC7594B-6D50-447C-908E-AE74172E288C}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{2AC7594B-6D50-447C-908E-AE74172E288C}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{2AC7594B-6D50-447C-908E-AE74172E288C}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {3F64EC58-7DAA-4691-880D-6031A55ABF6C}
24+
EndGlobalSection
25+
EndGlobal

EnLock/EnExtention.cs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
using System.Transactions;
7+
8+
namespace EnLock
9+
{
10+
public static class EnExtention
11+
{
12+
public static async Task<bool> ToAnyWithNoLockAsync<T>(this IQueryable<T> query, CancellationToken cancellationToken = default)
13+
{
14+
bool result = default;
15+
using (var scope = new TransactionScope(TransactionScopeOption.Required,
16+
new TransactionOptions()
17+
{
18+
IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted
19+
},
20+
TransactionScopeAsyncFlowOption.Enabled))
21+
{
22+
result = await query.AnyAsync(cancellationToken);
23+
scope.Complete();
24+
}
25+
return result;
26+
}
27+
public static async Task<T[]> ToArrayWithNoLockAsync<T>(this IQueryable<T> query, CancellationToken cancellationToken = default)
28+
{
29+
T[] result = default;
30+
using (var scope = new TransactionScope(TransactionScopeOption.Required,
31+
new TransactionOptions()
32+
{
33+
IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted
34+
},
35+
TransactionScopeAsyncFlowOption.Enabled))
36+
{
37+
result = await query.ToArrayAsync(cancellationToken);
38+
scope.Complete();
39+
}
40+
return result;
41+
}
42+
public static async Task<List<T>> ToListWithNoLockAsync<T>(this IQueryable<T> query, CancellationToken cancellationToken = default)
43+
{
44+
List<T> result = default;
45+
using (var scope = new TransactionScope(TransactionScopeOption.Required,
46+
new TransactionOptions()
47+
{
48+
IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted
49+
},
50+
TransactionScopeAsyncFlowOption.Enabled))
51+
{
52+
result = await query.ToListAsync(cancellationToken);
53+
scope.Complete();
54+
}
55+
return result;
56+
}
57+
public static async Task<T> ToFirstOrDefaultWithNoLockAsync<T>(this IQueryable<T> query, CancellationToken cancellationToken = default)
58+
{
59+
T result = default;
60+
using (var scope = new TransactionScope(TransactionScopeOption.Required,
61+
new TransactionOptions()
62+
{
63+
IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted
64+
},
65+
TransactionScopeAsyncFlowOption.Enabled))
66+
{
67+
result = await query.FirstOrDefaultAsync(cancellationToken);
68+
scope.Complete();
69+
}
70+
return result;
71+
}
72+
public static async Task<T> ToFirstWithNoLockAsync<T>(this IQueryable<T> query, CancellationToken cancellationToken = default)
73+
{
74+
T result = default;
75+
using (var scope = new TransactionScope(TransactionScopeOption.Required,
76+
new TransactionOptions()
77+
{
78+
IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted
79+
},
80+
TransactionScopeAsyncFlowOption.Enabled))
81+
{
82+
result = await query.FirstOrDefaultAsync(cancellationToken);
83+
scope.Complete();
84+
}
85+
return result;
86+
}
87+
public static async Task<T> ToSingleWithNoLockAsync<T>(this IQueryable<T> query, CancellationToken cancellationToken = default)
88+
{
89+
T result = default;
90+
using (var scope = new TransactionScope(TransactionScopeOption.Required,
91+
new TransactionOptions()
92+
{
93+
IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted
94+
},
95+
TransactionScopeAsyncFlowOption.Enabled))
96+
{
97+
result = await query.SingleAsync(cancellationToken);
98+
scope.Complete();
99+
}
100+
return result;
101+
}
102+
}
103+
}

EnLock/EnLock.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.1</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.0.1" />
10+
</ItemGroup>
11+
12+
</Project>

0 commit comments

Comments
 (0)