Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit ebcfaf4

Browse files
committed
Merge pull request #466 from rsafier/master
Extends support for output parameters with T4 template generated SPs
2 parents df9017b + 805be36 commit ebcfaf4

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

src/ServiceStack.OrmLite/OrmLiteSPStatement.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ public class OrmLiteSPStatement : IDisposable
1010
private readonly IDbCommand dbCmd;
1111
private readonly IOrmLiteDialectProvider dialectProvider;
1212

13+
public bool TryGetParameterValue(string parameterName, out object value)
14+
{
15+
try
16+
{
17+
value = ((IDataParameter)dbCmd.Parameters[parameterName]).Value;
18+
return true;
19+
}
20+
catch(Exception)
21+
{
22+
value = null;
23+
return false;
24+
}
25+
}
26+
1327
public OrmLiteSPStatement(IDbCommand dbCmd)
1428
: this(null, dbCmd) {}
1529

src/T4/OrmLite.Core.ttinclude

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,21 @@ List<SP> SPsNotSupported(string providerName)
592592
return new List<SP>();
593593
}
594594

595+
string GetParamDirection(SPParamDir direction)
596+
{
597+
switch(direction)
598+
{
599+
case SPParamDir.InAndOutDirection:
600+
return "ParameterDirection.InputOutput";
601+
case SPParamDir.OutDirection:
602+
return "ParameterDirection.Output";
603+
case SPParamDir.InDirection:
604+
default:
605+
return "ParameterDirection.Input";
606+
}
607+
}
608+
609+
595610
List<SP> LoadSPs()
596611
{
597612
InitConnectionString();

src/T4/OrmLite.SP.tt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ namespace <#=SPNamespace#>
3838
}
3939

4040
<#foreach(var sp in sps){#>
41-
public static OrmLiteSPStatement <#=sp.CleanName#>(this IDbConnection db<#foreach(var param in sp.Parameters){#>, <#=param.NullableSysType#> <#=Inflector.MakeInitialLowerCase(param.Name)#> = null<#}#>)
41+
public static OrmLiteSPStatement <#=sp.CleanName#>(this IDbConnection db<#foreach(var param in sp.Parameters){#>, <#=param.NullableSysType#> @<#=Inflector.MakeInitialLowerCase(param.Name)#> = null<#}#>)
4242
{
4343
var dbCmd = (DbCommand)OrmLiteConfig.ExecFilter.CreateCommand(db).ToDbCommand();
4444
dbCmd.CommandText = "<#=sp.Name#>";
4545
dbCmd.CommandType = CommandType.StoredProcedure;
4646
<#if (sp.Parameters.Count > 0) { foreach(var param in sp.Parameters){#>
47-
dbCmd.Parameters.Add(CreateNewParameter(dbCmd,"<#=param.Name#>",<#=Inflector.MakeInitialLowerCase(param.Name)#>,ParameterDirection.Input,<#=param.DbType#>));
47+
dbCmd.Parameters.Add(CreateNewParameter(dbCmd,"<#=param.Name#>",@<#=Inflector.MakeInitialLowerCase(param.Name)#>,<#=GetParamDirection(param.Direction)#>,<#=param.DbType#>));
4848
<#}#> <#}#>
4949
return new OrmLiteSPStatement(db, dbCmd);
5050
}

0 commit comments

Comments
 (0)