mirror of
https://github.com/FalconWu2017/Falcon.StoredProcedureRunner.git
synced 2025-04-10 09:29:37 +08:00
支持定义存储过程参数类型
This commit is contained in:
parent
9044a859ef
commit
2b8c470728
|
@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 16
|
# Visual Studio Version 16
|
||||||
VisualStudioVersion = 16.0.30804.86
|
VisualStudioVersion = 16.0.30804.86
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Falcon.StoredProcedureRunner", "Falcon.StoredProcedureRunner\Falcon.StoredProcedureRunner.csproj", "{13D3139B-60C2-4785-ADCB-4F839BDEC3C4}"
|
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}") = "Falcon.StoredProcedureRunner.Example", "Falcon.StoredProcedureRunner.Example\Falcon.StoredProcedureRunner.Example.csproj", "{3D5C85F0-94BF-487E-8418-B39FF3505262}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
@ -15,6 +17,10 @@ Global
|
||||||
{13D3139B-60C2-4785-ADCB-4F839BDEC3C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{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.ActiveCfg = Release|Any CPU
|
||||||
{13D3139B-60C2-4785-ADCB-4F839BDEC3C4}.Release|Any CPU.Build.0 = Release|Any CPU
|
{13D3139B-60C2-4785-ADCB-4F839BDEC3C4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{3D5C85F0-94BF-487E-8418-B39FF3505262}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{3D5C85F0-94BF-487E-8418-B39FF3505262}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{3D5C85F0-94BF-487E-8418-B39FF3505262}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{3D5C85F0-94BF-487E-8418-B39FF3505262}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
using System;
|
||||||
|
using System.Data;
|
||||||
|
|
||||||
|
namespace Falcon.StoredProcedureRunner
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 定义存储过程参数类型
|
||||||
|
/// </summary>
|
||||||
|
public class FalconSPPrarmTypeAttribute:Attribute
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 参数名
|
||||||
|
/// </summary>
|
||||||
|
public SqlDbType PType { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 定于存储过程参数名称
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pType">参数类型</param>
|
||||||
|
public FalconSPPrarmTypeAttribute(SqlDbType pType) { this.PType = pType; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
@ -137,10 +138,29 @@ namespace Falcon.StoredProcedureRunner
|
||||||
foreach(var p in typeof(T).GetProperties()) {
|
foreach(var p in typeof(T).GetProperties()) {
|
||||||
if(!p.CanRead || ignoreProp(p))
|
if(!p.CanRead || ignoreProp(p))
|
||||||
continue;
|
continue;
|
||||||
yield return new SqlParameter($"@{getPrarmName(p)}",p.GetValue(data));
|
var pt = getPrarmType(p);
|
||||||
|
if(pt.HasValue) {
|
||||||
|
var np = new SqlParameter($"@{getPrarmName(p)}",pt);
|
||||||
|
np.Value = p.GetValue(data);
|
||||||
|
yield return np;
|
||||||
|
} else {
|
||||||
|
yield return new SqlParameter($"@{getPrarmName(p)}",p.GetValue(data));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取存储过程参数类型
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="p">对应的属性</param>
|
||||||
|
private static SqlDbType? getPrarmType(PropertyInfo p) {
|
||||||
|
var np = p.GetCustomAttribute<FalconSPPrarmTypeAttribute>(true);
|
||||||
|
if(np != null && np is FalconSPPrarmTypeAttribute na) {
|
||||||
|
return na.PType;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否忽略属性
|
/// 是否忽略属性
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user