Skip to content

Commit ebd2539

Browse files
Merge pull request #32 from Lempireqc/master
save async
2 parents b0c29b5 + c439212 commit ebd2539

File tree

11 files changed

+423
-21
lines changed

11 files changed

+423
-21
lines changed

EntityFrameworkExtras.EF6.Net45/EntityFrameworkExtras.EF6.Net45.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<DebugType>full</DebugType>
1919
<Optimize>false</Optimize>
2020
<OutputPath>bin\Debug\</OutputPath>
21-
<DefineConstants>TRACE;DEBUG;EF6</DefineConstants>
21+
<DefineConstants>TRACE;DEBUG;EF6 NET45</DefineConstants>
2222
<ErrorReport>prompt</ErrorReport>
2323
<WarningLevel>4</WarningLevel>
2424
<Prefer32Bit>false</Prefer32Bit>
@@ -27,7 +27,7 @@
2727
<DebugType>pdbonly</DebugType>
2828
<Optimize>true</Optimize>
2929
<OutputPath>bin\Release\</OutputPath>
30-
<DefineConstants>TRACE;EF6</DefineConstants>
30+
<DefineConstants>TRACE;EF6 NET45</DefineConstants>
3131
<ErrorReport>prompt</ErrorReport>
3232
<WarningLevel>4</WarningLevel>
3333
<Prefer32Bit>false</Prefer32Bit>

EntityFrameworkExtras.EF6.NetStandard/EntityFrameworkExtras.EF6.NetStandard.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
</PropertyGroup>
1515

1616
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
17-
<DefineConstants>TRACE;EF6</DefineConstants>
17+
<DefineConstants>TRACE;EF6 NET45</DefineConstants>
1818
</PropertyGroup>
1919

2020
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
21-
<DefineConstants>TRACE;EF6</DefineConstants>
21+
<DefineConstants>TRACE;EF6 NET45</DefineConstants>
2222
<DocumentationFile>bin\Release\netstandard2.1\EntityFrameworkExtras.EF6.xml</DocumentationFile>
2323
<OutputPath>bin\Release\</OutputPath>
2424
</PropertyGroup>

EntityFrameworkExtras.EFCore.sln

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "EntityFrameworkExtras.Tests
1414
EndProject
1515
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "EFCore", "EFCore", "{9E15663E-75C8-43B6-8236-4847A2685D42}"
1616
EndProject
17-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityFrameworkExtras.EFCore3", "EntityFrameworkExtras.EFCore3\EntityFrameworkExtras.EFCore3.csproj", "{C1144C22-BE1B-4179-B667-51C7D14A3E41}"
18-
EndProject
1917
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFrameworkExtras.EFCore3.Tests", "EntityFrameworkExtras.EFCore3.Tests\EntityFrameworkExtras.EFCore3.Tests.csproj", "{59943B99-772A-47E4-AA70-6D758312C00C}"
2018
EndProject
19+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityFrameworkExtras.EFCore3.NetStandard21", "EntityFrameworkExtras.EFCore3.NetStandard21\EntityFrameworkExtras.EFCore3.NetStandard21.csproj", "{94101B83-CD6B-4F8A-9AB9-93A0D3371D07}"
20+
EndProject
2121
Global
2222
GlobalSection(SharedMSBuildProjectFiles) = preSolution
2323
EntityFrameworkExtras.Tests.Shared\EntityFrameworkExtras.Tests.Shared.projitems*{59943b99-772a-47e4-aa70-6d758312c00c}*SharedItemsImports = 4
@@ -29,20 +29,19 @@ Global
2929
Release|Any CPU = Release|Any CPU
3030
EndGlobalSection
3131
GlobalSection(ProjectConfigurationPlatforms) = postSolution
32-
{C1144C22-BE1B-4179-B667-51C7D14A3E41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33-
{C1144C22-BE1B-4179-B667-51C7D14A3E41}.Debug|Any CPU.Build.0 = Debug|Any CPU
34-
{C1144C22-BE1B-4179-B667-51C7D14A3E41}.Release|Any CPU.ActiveCfg = Release|Any CPU
35-
{C1144C22-BE1B-4179-B667-51C7D14A3E41}.Release|Any CPU.Build.0 = Release|Any CPU
3632
{59943B99-772A-47E4-AA70-6D758312C00C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
3733
{59943B99-772A-47E4-AA70-6D758312C00C}.Debug|Any CPU.Build.0 = Debug|Any CPU
3834
{59943B99-772A-47E4-AA70-6D758312C00C}.Release|Any CPU.ActiveCfg = Release|Any CPU
3935
{59943B99-772A-47E4-AA70-6D758312C00C}.Release|Any CPU.Build.0 = Release|Any CPU
36+
{94101B83-CD6B-4F8A-9AB9-93A0D3371D07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37+
{94101B83-CD6B-4F8A-9AB9-93A0D3371D07}.Debug|Any CPU.Build.0 = Debug|Any CPU
38+
{94101B83-CD6B-4F8A-9AB9-93A0D3371D07}.Release|Any CPU.ActiveCfg = Release|Any CPU
39+
{94101B83-CD6B-4F8A-9AB9-93A0D3371D07}.Release|Any CPU.Build.0 = Release|Any CPU
4040
EndGlobalSection
4141
GlobalSection(SolutionProperties) = preSolution
4242
HideSolutionNode = FALSE
4343
EndGlobalSection
4444
GlobalSection(NestedProjects) = preSolution
45-
{C1144C22-BE1B-4179-B667-51C7D14A3E41} = {9E15663E-75C8-43B6-8236-4847A2685D42}
4645
{59943B99-772A-47E4-AA70-6D758312C00C} = {9E15663E-75C8-43B6-8236-4847A2685D42}
4746
EndGlobalSection
4847
GlobalSection(ExtensibilityGlobals) = postSolution

EntityFrameworkExtras.EFCore3.Tests/EntityFrameworkExtras.EFCore3.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
</Reference>
4444
<Reference Include="Microsoft.Data.SqlClient, Version=1.0.19269.1, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5, processorArchitecture=MSIL">
4545
<HintPath>..\packages\Microsoft.Data.SqlClient.1.0.19269.1\lib\net46\Microsoft.Data.SqlClient.dll</HintPath>
46+
<Private>True</Private>
4647
</Reference>
4748
<Reference Include="Microsoft.EntityFrameworkCore, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
4849
<HintPath>..\packages\Microsoft.EntityFrameworkCore.3.1.0\lib\netstandard2.0\Microsoft.EntityFrameworkCore.dll</HintPath>
@@ -55,6 +56,7 @@
5556
</Reference>
5657
<Reference Include="Microsoft.EntityFrameworkCore.SqlServer, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
5758
<HintPath>..\packages\Microsoft.EntityFrameworkCore.SqlServer.3.1.0\lib\netstandard2.0\Microsoft.EntityFrameworkCore.SqlServer.dll</HintPath>
59+
<Private>True</Private>
5860
</Reference>
5961
<Reference Include="Microsoft.Extensions.Caching.Abstractions, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
6062
<HintPath>..\packages\Microsoft.Extensions.Caching.Abstractions.3.1.0\lib\netstandard2.0\Microsoft.Extensions.Caching.Abstractions.dll</HintPath>

EntityFrameworkExtras.EFCore3.lab/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Program
66
{
77
static void Main(string[] args)
88
{
9-
Request_storeProcedure_Transaction.Execute();
9+
Request_Async.Execute();
1010
}
1111
}
1212
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using EntityFrameworkExtras.EFCore;
9+
using Microsoft.Data.SqlClient;
10+
using Microsoft.EntityFrameworkCore;
11+
12+
namespace Z.EntityFrameworkExtras.Lab.EFCore30
13+
{
14+
class Request_Async
15+
{
16+
public static void Execute()
17+
{
18+
// Create BD
19+
using (var context = new EntityContext())
20+
{
21+
My.CreateBD(context);
22+
}
23+
24+
// CLEAN
25+
using (var context = new EntityContext())
26+
{
27+
context.EntitySimples.RemoveRange(context.EntitySimples);
28+
29+
context.SaveChanges();
30+
}
31+
32+
// SEED
33+
using (var context = new EntityContext())
34+
{
35+
for (int i = 0; i < 3; i++)
36+
{
37+
context.EntitySimples.Add(new EntitySimple { ColumnInt = i });
38+
}
39+
40+
context.SaveChanges();
41+
}
42+
43+
44+
45+
// TEST
46+
using (var context = new EntityContext())
47+
{
48+
var connection = context.Database.GetDbConnection();
49+
connection.Open();
50+
using (var commande = connection.CreateCommand())
51+
{
52+
commande.CommandText = @"
53+
if exists (select 1 from sys.procedures where name = 'PROC_Get_EntitySimple')
54+
BEGIN
55+
DROP PROCEDURE [dbo].[PROC_Get_EntitySimple]
56+
END
57+
";
58+
commande.ExecuteNonQuery();
59+
}
60+
61+
using (var commande = connection.CreateCommand())
62+
{
63+
commande.CommandText = @"
64+
CREATE PROCEDURE [dbo].[PROC_Get_EntitySimple]
65+
66+
@ParameterID INT ,
67+
@ParameterInt INT = NULL OUTPUT
68+
69+
70+
AS
71+
BEGIN
72+
73+
WAITFOR DELAY '00:00:05'
74+
Select * from EntitySimples
75+
Where ColumnInt = @ParameterID
76+
Set @ParameterInt = @ParameterID +1
77+
END
78+
";
79+
commande.ExecuteNonQuery();
80+
}
81+
82+
}
83+
84+
// TEST
85+
using (var context = new EntityContext())
86+
{
87+
var cts = new CancellationTokenSource();
88+
89+
var proc_Get_EntitySimple = new Proc_Get_EntitySimple() { ParameterID = 2 };
90+
var entity = context.Database.ExecuteStoredProcedureAsync<EntitySimple>(proc_Get_EntitySimple, cts.Token) ;
91+
// cts.Cancel();
92+
entity.Wait();
93+
}
94+
95+
96+
using (var context = new EntityContext())
97+
{
98+
var cts = new CancellationTokenSource();
99+
var proc_Get_EntitySimple = new Proc_Get_EntitySimple() { ParameterID = 2 };
100+
var task = context.Database.ExecuteStoredProcedureAsync(proc_Get_EntitySimple, cts.Token);
101+
// cts.Cancel();
102+
task.Wait();
103+
}
104+
}
105+
106+
public class EntityContext : DbContext
107+
{
108+
public EntityContext() : base( )
109+
{
110+
}
111+
112+
public DbSet<EntitySimple> EntitySimples { get; set; }
113+
114+
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
115+
{
116+
optionsBuilder.UseSqlServer(new SqlConnection(My.ConnectionString));
117+
118+
base.OnConfiguring(optionsBuilder);
119+
}
120+
}
121+
122+
[StoredProcedure("PROC_Get_EntitySimple")]
123+
public class Proc_Get_EntitySimple
124+
{
125+
[StoredProcedureParameter(SqlDbType.Int, Direction = ParameterDirection.Output)]
126+
public int ParameterInt { get; set; }
127+
128+
[StoredProcedureParameter(SqlDbType.Int, Direction = ParameterDirection.Input)]
129+
public int ParameterID { get; set; }
130+
}
131+
132+
public class EntitySimple
133+
{
134+
public int ID { get; set; }
135+
public int ColumnInt { get; set; }
136+
public String ColumnString { get; set; }
137+
}
138+
}
139+
}

0 commit comments

Comments
 (0)