From a9d997452a09128068d4224870d1d7e59b1292f6 Mon Sep 17 00:00:00 2001 From: falcon <9504402@qq.com> Date: Mon, 14 Dec 2020 10:53:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=BB=BA=E6=A0=B7=E4=BE=8B=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Database/MyDb.cs | 22 ++++++++ .../Database/sp/Sp1.cs | 50 +++++++++++++++++++ ...aclon.StoredProcedureRunner.Example.csproj | 18 +++++++ .../Program.cs | 27 ++++++++++ src/Falcon.StoredProcedureRunner.sln | 6 +++ 5 files changed, 123 insertions(+) create mode 100644 src/Faclon.StoredProcedureRunner.Example/Database/MyDb.cs create mode 100644 src/Faclon.StoredProcedureRunner.Example/Database/sp/Sp1.cs create mode 100644 src/Faclon.StoredProcedureRunner.Example/Faclon.StoredProcedureRunner.Example.csproj create mode 100644 src/Faclon.StoredProcedureRunner.Example/Program.cs diff --git a/src/Faclon.StoredProcedureRunner.Example/Database/MyDb.cs b/src/Faclon.StoredProcedureRunner.Example/Database/MyDb.cs new file mode 100644 index 0000000..9d7b5f9 --- /dev/null +++ b/src/Faclon.StoredProcedureRunner.Example/Database/MyDb.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Faclon.StoredProcedureRunner.Example.Database.sp; +using Microsoft.EntityFrameworkCore; +using Falcon.StoredProcedureRunner; + +namespace Faclon.StoredProcedureRunner.Example.Database +{ + public class MyDb:DbContext + { + public IRunner SpRunner { get; set; } + + public MyDb(DbContextOptions options,IRunner spRunner) : base(options) { + this.SpRunner = spRunner; + } + + public IEnumerable RunSp1(Sp1 data) { + return this.SpRunner.Run(this,data); + } + } +} diff --git a/src/Faclon.StoredProcedureRunner.Example/Database/sp/Sp1.cs b/src/Faclon.StoredProcedureRunner.Example/Database/sp/Sp1.cs new file mode 100644 index 0000000..a205fcd --- /dev/null +++ b/src/Faclon.StoredProcedureRunner.Example/Database/sp/Sp1.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Falcon.StoredProcedureRunner; + +namespace Faclon.StoredProcedureRunner.Example.Database.sp +{ + /// + /// 测试用存储过程 + /// + [FalconSPReturnType(typeof(Sp1_Result))] + [FalconSPProcuderName("TestSp1")] + public class Sp1 + { + /// + /// 整数1 + /// + public int P1 { get; set; } = 1; + /// + /// 整数2 + /// + public int P2 { get; set; } = 2; + } + /// + /// 存储过程执行结果 + /// + public class Sp1_Result + { + /// + /// 结果行号 + /// + public int Id { get; set; } + /// + /// 求和 + /// + public int Jia { get; set; } + /// + /// 求差 + /// + public int Jian { get; set; } + /// + /// 求乘积 + /// + public int Chen { get; set; } + /// + /// 求除法 + /// + public double Chu { get; set; } + } +} diff --git a/src/Faclon.StoredProcedureRunner.Example/Faclon.StoredProcedureRunner.Example.csproj b/src/Faclon.StoredProcedureRunner.Example/Faclon.StoredProcedureRunner.Example.csproj new file mode 100644 index 0000000..4b25f10 --- /dev/null +++ b/src/Faclon.StoredProcedureRunner.Example/Faclon.StoredProcedureRunner.Example.csproj @@ -0,0 +1,18 @@ + + + + Exe + netcoreapp3.1 + + + + + + + + + + + + + diff --git a/src/Faclon.StoredProcedureRunner.Example/Program.cs b/src/Faclon.StoredProcedureRunner.Example/Program.cs new file mode 100644 index 0000000..1536fb7 --- /dev/null +++ b/src/Faclon.StoredProcedureRunner.Example/Program.cs @@ -0,0 +1,27 @@ +using System; +using System.Linq; +using Faclon.StoredProcedureRunner.Example.Database; +using Falcon.StoredProcedureRunner; +using Microsoft.EntityFrameworkCore; + +namespace Faclon.StoredProcedureRunner.Example +{ + class Program + { + static void Main(string[] args) { + IRunner runner = new Runner(); + var conStr = "Server =.\\SQLSERVER2008R2;Database = test;User ID = sa;Password = 111"; + var opb = new DbContextOptionsBuilder(); + opb.UseSqlServer(conStr); + var db = new MyDb(opb.Options,runner); + var r = db.RunSp1(new Database.sp.Sp1()); + Console.WriteLine("返回记录数{0},应该为2",r.Count()); + var fir = r.First(); + Console.WriteLine("Id为{0},应该为1",fir.Id); + Console.WriteLine("Jia{0},应该为3",fir.Jia); + Console.WriteLine("Jian{0},应该为-1",fir.Jian); + Console.WriteLine("Chen{0},应该为2",fir.Chen); + Console.WriteLine("Chu{0},应该为0.5",fir.Chu); + } + } +} diff --git a/src/Falcon.StoredProcedureRunner.sln b/src/Falcon.StoredProcedureRunner.sln index 1e0aa54..cc11cfa 100644 --- a/src/Falcon.StoredProcedureRunner.sln +++ b/src/Falcon.StoredProcedureRunner.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.30804.86 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Falcon.StoredProcedureRunner", "Falcon.StoredProcedureRunner\Falcon.StoredProcedureRunner.csproj", "{13D3139B-60C2-4785-ADCB-4F839BDEC3C4}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Faclon.StoredProcedureRunner.Example", "Faclon.StoredProcedureRunner.Example\Faclon.StoredProcedureRunner.Example.csproj", "{40610016-0C9C-462D-B352-49D6C33DA5FC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {13D3139B-60C2-4785-ADCB-4F839BDEC3C4}.Debug|Any CPU.Build.0 = Debug|Any CPU {13D3139B-60C2-4785-ADCB-4F839BDEC3C4}.Release|Any CPU.ActiveCfg = Release|Any CPU {13D3139B-60C2-4785-ADCB-4F839BDEC3C4}.Release|Any CPU.Build.0 = Release|Any CPU + {40610016-0C9C-462D-B352-49D6C33DA5FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {40610016-0C9C-462D-B352-49D6C33DA5FC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {40610016-0C9C-462D-B352-49D6C33DA5FC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {40610016-0C9C-462D-B352-49D6C33DA5FC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE