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

Commit d05650d

Browse files
author
Wim Pool
committed
Update src/T4/OrmLite.Poco.tt
Added 3 new options: - MakeSingular, default true. if true: Changes the classname to singular if tablename is not singular - UseIdAsPk, default true. if true: Changes the primary key property name to Id - GenerateConstructor, default false. if true: Generates the default empty constructor
1 parent 23a39fc commit d05650d

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/T4/OrmLite.Poco.tt

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
Namespace = "";
66
ClassPrefix = "";
77
ClassSuffix = "";
8-
bool SplitIntoMultipleFiles = false;
8+
bool SplitIntoMultipleFiles = false; // if true: Generates one file for every class
9+
bool MakeSingular = true; // if true: Changes the classname to singular if tablename is not singular
10+
bool UseIdAsPK = true; // if true: Changes the primary key property name to Id
11+
bool GenerateConstructor = false; // if true: Generates the default empty constructor
912

1013
// Read schema
11-
var tables = LoadTables();
14+
var tables = LoadTables(MakeSingular);
1215

1316

1417
/*
@@ -53,14 +56,20 @@ foreach(Table tbl in from t in tables where !t.Ignore select t)
5356
{
5457
manager.StartNewFile(tbl.Name + ".cs");
5558
#>
56-
59+
<# if (MakeSingular) {#>
5760
[Alias("<#=tbl.Name#>")]
58-
public partial class <#=tbl.ClassName#><#if (tbl.HasPK()) { #> : IHasId<<#=tbl.PK.PropertyType#>><#}#>
61+
<#}#>
62+
public partial class <#=tbl.ClassName#><#if (tbl.HasPK() && UseIdAsPK) { #> : IHasId<<#=tbl.PK.PropertyType#>><#}#>
5963
{
60-
<#
64+
<# if (GenerateConstructor) { #>
65+
public <#=tbl.ClassName#>()
66+
{
67+
}
68+
69+
<# }
6170
foreach(Column col in from c in tbl.Columns where !c.Ignore select c)
6271
{
63-
if ((col.Name!=col.PropertyName) || (col.IsPK)) { #>
72+
if ((col.Name!=col.PropertyName) || (col.IsPK && UseIdAsPK)) { #>
6473
[Alias("<#=col.Name#>")]
6574
<# } if (col.PropertyType == "string" && col.Size > 0) { #>
6675
[StringLength(<#=col.Size#>)]
@@ -70,9 +79,12 @@ foreach(Column col in from c in tbl.Columns where !c.Ignore select c)
7079
[Required]
7180
<# } if (!col.IsPK){#>
7281
public <#=col.ProperPropertyType#> <#=col.PropertyName#> { get; set;}
73-
<#} else {#>
82+
<# } if (col.IsPK && UseIdAsPK) { #>
7483
public <#=col.ProperPropertyType#> Id { get; set;}
75-
<#}#>
84+
<# } if (col.IsPK && !UseIdAsPK) { #>
85+
[PrimaryKey]
86+
public <#=col.ProperPropertyType#> <#=col.PropertyName#> { get; set;}
87+
<# } #>
7688
<# } #>
7789
}
7890
<# manager.EndBlock(); #>

0 commit comments

Comments
 (0)