1 <#@ include file="OrmLite.Core.ttinclude" #>
4 ConnectionStringName = ""; // Uses last connection string in config if not specified
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
12 bool UseSchemaAttribute = true; // if true: Adds explicit '[Schema]' attribute
15 var tables = LoadTables(MakeSingular);
20 tables["tablename"].Ignore = true; // To ignore a table
21 tables["tablename"].ClassName = "newname"; // To change the class name of a table
22 tables["tablename"]["columnname"].Ignore = true; // To ignore a column
23 tables["tablename"]["columnname"].PropertyName="newname"; // To change the property name of a column
24 tables["tablename"]["columnname"].PropertyType="bool"; // To change the property type of a column
32 if (string.IsNullOrEmpty(Namespace)) Namespace=ConnectionStringName;
33 if (string.IsNullOrEmpty(Namespace)) Namespace="OrmLitePoco";
34 var manager = Manager.Create(Host, GenerationEnvironment);
35 manager.StartHeader(); #>// <auto-generated />
36 // This file was generated by a T4 template.
37 // Don't change it directly as your change would get overwritten. Instead, make changes
38 // to the .tt file (i.e. the T4 template) and save it to regenerate this file.
40 // Make sure the compiler doesn't complain about missing Xml comments
41 #pragma warning disable 1591
44 using System.Collections.Generic;
48 using ServiceStack.OrmLite;
49 using ServiceStack.DataAnnotations;
50 using ServiceStack.Model;
52 namespace <#=Namespace #>
54 <#manager.EndBlock(); #>
56 foreach(Table tbl in from t in tables where !t.Ignore select t)
58 manager.StartNewFile(tbl.Name + ".cs");
60 <# if (MakeSingular) {#>
61 [Alias("<#=tbl.Name#>")]
63 <# if (UseSchemaAttribute && !string.IsNullOrEmpty(tbl.Schema) && tbl.Schema != "dbo") {#>
64 [Schema("<#=tbl.Schema#>")]
66 public partial class <#=tbl.ClassName#><#if (tbl.HasPK() && UseIdAsPK) { #> : IHasId<<#=tbl.PK.PropertyType#>><#}#>
68 <# if (GenerateConstructor) { #>
69 public <#=tbl.ClassName#>()
74 foreach(Column col in from c in tbl.Columns where !c.Ignore select c)
76 if ((col.Name!=col.PropertyName) || (col.IsPK && UseIdAsPK)) { #>
77 [Alias("<#=col.Name#>")]
78 <# } if (col.PropertyType == "string" && col.Size > 0) { #>
79 [StringLength(<#=col.Size#>)]
80 <# } if (col.IsAutoIncrement) { #>
82 <# } if (col.IsComputed) { #>
84 <# } if (col.IsNullable != true && col.IsAutoIncrement != true) { #>
86 <# } if (!col.IsPK){#>
87 public <#=col.ProperPropertyType#> <#=col.PropertyName#> { get; set;}
88 <# } if (col.IsPK && UseIdAsPK) { #>
89 public <#=col.ProperPropertyType#> Id { get; set;}
90 <# } if (col.IsPK && !UseIdAsPK) { #>
92 public <#=col.ProperPropertyType#> <#=col.PropertyName#> { get; set;}
96 <# manager.EndBlock(); #>
98 <#manager.StartFooter(); #>
100 #pragma warning restore 1591
101 <#manager.EndBlock(); #>
102 <#manager.Process(SplitIntoMultipleFiles); #>