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

Commit 65553e0

Browse files
committed
Merge pull request #474 from rsafier/master
Further refinements on POCO and SP templates
2 parents deb1231 + 15006cf commit 65553e0

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

src/T4/OrmLite.Core.ttinclude

+10-4
Original file line numberDiff line numberDiff line change
@@ -1007,13 +1007,19 @@ class SqlServerSchemaReader : SchemaReader
10071007
{
10081008
SPOutputColumn param=new SPOutputColumn();
10091009
param.Name = rdr["name"].ToString();
1010-
if (rdr["is_nullable"] == "0")
1011-
{
1012-
param.DotNetType = GetPropertyType(rdr["system_type_name"].ToString());
1010+
1011+
var sqlType = rdr["system_type_name"].ToString();
1012+
var index = sqlType.IndexOf('('); //Trim off size data
1013+
if (index > 0) sqlType = sqlType.Substring(0,index);
1014+
1015+
var nullable = rdr["is_nullable"].ToString() ;
1016+
if (nullable == "0")
1017+
{
1018+
param.DotNetType = GetPropertyType(sqlType);
10131019
}
10141020
else
10151021
{
1016-
param.DotNetType = GetNullablePropertyType(rdr["system_type_name"].ToString());
1022+
param.DotNetType = GetNullablePropertyType(sqlType);
10171023
}
10181024
if (!result.Any(t=>t.Name == param.Name)) result.Add(param);
10191025
}

src/T4/OrmLite.Poco.tt

+6-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,14 @@ manager.StartNewFile(tbl.Name + ".cs");
7171
}
7272

7373
<# }
74+
var priorProperyNames = new List<string>();
7475
foreach(Column col in from c in tbl.Columns where !c.Ignore select c)
7576
{
77+
if (priorProperyNames.Contains(col.PropertyName)) //Change duplicate style names
78+
{
79+
col.PropertyName = "_" + col.PropertyName;
80+
}
81+
priorProperyNames.Add(col.PropertyName);
7682
if ((col.Name!=col.PropertyName) || (col.IsPK && UseIdAsPK)) { #>
7783
[Alias("<#=col.Name#>")]
7884
<# } if (col.PropertyType == "string" && col.Size > 0) { #>
@@ -101,5 +107,3 @@ foreach(Column col in from c in tbl.Columns where !c.Ignore select c)
101107
<#manager.EndBlock(); #>
102108
<#manager.Process(SplitIntoMultipleFiles); #>
103109
<# } #>
104-
105-

src/T4/OrmLite.SP.tt

+9-8
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace <#=SPNamespace#>
4747
<#if (sp.Parameters.Count > 0) { foreach(var param in sp.Parameters){#>
4848
dbCmd.Parameters.Add(CreateNewParameter(dbCmd,"<#=param.Name#>",@<#=Inflector.MakeInitialLowerCase(param.Name)#>,<#=GetParamDirection(param.Direction)#>,<#=param.DbType#>));
4949
<#}#> <#}#>
50-
dbCmd.Parameters.Add(CreateNewParameter(dbCmd,"__ReturnValue",0,ParameterDirection.ReturnValue,DbType.Int32));
50+
dbCmd.Parameters.Add(CreateNewParameter(dbCmd,"__ReturnValue",0,ParameterDirection.ReturnValue,DbType.Int32));
5151
return new OrmLiteSPStatement(db, dbCmd);
5252
}
5353

@@ -59,13 +59,14 @@ dbCmd.Parameters.Add(CreateNewParameter(dbCmd,"__ReturnValue",0,ParameterDirecti
5959
if (!sp.SPOutputColumns.Any()) continue; #>
6060
public class <#=sp.CleanName#>_Result
6161
{
62-
<# foreach(var prop in sp.SPOutputColumns){ if (char.IsDigit(prop.Name[0])) { #>
63-
[Alias("<#=prop.Name#>")]
64-
public <#=prop.DotNetType#> _<#=prop.Name#> { get; set; }
65-
<#} else {#>
66-
public <#=prop.DotNetType#> <#=prop.Name#> { get; set; }
67-
<#}}#>
68-
}
62+
<# foreach(var prop in sp.SPOutputColumns) { var alias = false; var propName = prop.Name; if (propName.Contains(' ') || propName.Contains('$') || propName.Contains('+')) { propName = propName.Replace(' ','_').Replace("$","_Dollar").Replace("+","_Plus"); alias = true; }; if (char.IsDigit(propName[0])) { propName = "_" + propName; alias = true; };
63+
64+
if (alias) {#> [Alias("<#=prop.Name#>")]
65+
<#}#>
66+
public <#=prop.DotNetType#> <#=propName#> { get; set; }
67+
<#}
68+
#>
69+
}
6970
<#}#>
7071

7172
}

0 commit comments

Comments
 (0)