mirror of
https://github.com/FalconWu2017/Falcon.StoredProcedureRunner.git
synced 2024-11-23 05:29:37 +08:00
新建样例项目
This commit is contained in:
parent
b031355576
commit
a9d997452a
22
src/Faclon.StoredProcedureRunner.Example/Database/MyDb.cs
Normal file
22
src/Faclon.StoredProcedureRunner.Example/Database/MyDb.cs
Normal file
|
@ -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<Sp1_Result> RunSp1(Sp1 data) {
|
||||
return this.SpRunner.Run<Sp1,Sp1_Result>(this,data);
|
||||
}
|
||||
}
|
||||
}
|
50
src/Faclon.StoredProcedureRunner.Example/Database/sp/Sp1.cs
Normal file
50
src/Faclon.StoredProcedureRunner.Example/Database/sp/Sp1.cs
Normal file
|
@ -0,0 +1,50 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Falcon.StoredProcedureRunner;
|
||||
|
||||
namespace Faclon.StoredProcedureRunner.Example.Database.sp
|
||||
{
|
||||
/// <summary>
|
||||
/// 测试用存储过程
|
||||
/// </summary>
|
||||
[FalconSPReturnType(typeof(Sp1_Result))]
|
||||
[FalconSPProcuderName("TestSp1")]
|
||||
public class Sp1
|
||||
{
|
||||
/// <summary>
|
||||
/// 整数1
|
||||
/// </summary>
|
||||
public int P1 { get; set; } = 1;
|
||||
/// <summary>
|
||||
/// 整数2
|
||||
/// </summary>
|
||||
public int P2 { get; set; } = 2;
|
||||
}
|
||||
/// <summary>
|
||||
/// 存储过程执行结果
|
||||
/// </summary>
|
||||
public class Sp1_Result
|
||||
{
|
||||
/// <summary>
|
||||
/// 结果行号
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
/// <summary>
|
||||
/// 求和
|
||||
/// </summary>
|
||||
public int Jia { get; set; }
|
||||
/// <summary>
|
||||
/// 求差
|
||||
/// </summary>
|
||||
public int Jian { get; set; }
|
||||
/// <summary>
|
||||
/// 求乘积
|
||||
/// </summary>
|
||||
public int Chen { get; set; }
|
||||
/// <summary>
|
||||
/// 求除法
|
||||
/// </summary>
|
||||
public double Chu { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Falcon.StoredProcedureRunner\Falcon.StoredProcedureRunner.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Data.SqlClient" Version="2.1.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
27
src/Faclon.StoredProcedureRunner.Example/Program.cs
Normal file
27
src/Faclon.StoredProcedureRunner.Example/Program.cs
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user