initial commit
[CPE_learningsite] / CPE / CPE.App / CPE.App.Api / OrmLite.Poco.tt
1 <#@ include file="OrmLite.Core.ttinclude" #>
2 <#
3         // Settings
4         ConnectionStringName = "";                      // Uses last connection string in config if not specified
5         Namespace = "";
6         ClassPrefix = "";
7         ClassSuffix = "";
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
13
14     // Read schema
15         var tables = LoadTables(MakeSingular);
16
17
18 /*
19         // Tweak Schema
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
25 */
26
27         // Generate output
28         if (tables.Count>0)
29         {
30 #>
31 <#
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.
39
40 // Make sure the compiler doesn't complain about missing Xml comments
41 #pragma warning disable 1591
42
43 using System;
44 using System.Collections.Generic;
45 using System.Linq;
46 using System.Web;
47
48 using ServiceStack.OrmLite;
49 using ServiceStack.DataAnnotations;
50 using ServiceStack.Model;
51
52 namespace <#=Namespace #>
53 {
54 <#manager.EndBlock(); #>
55 <#
56 foreach(Table tbl in from t in tables where !t.Ignore select t)
57 {
58 manager.StartNewFile(tbl.Name + ".cs");
59 #>
60 <# if (MakeSingular) {#>
61         [Alias("<#=tbl.Name#>")]
62 <#}#>
63 <# if (UseSchemaAttribute && !string.IsNullOrEmpty(tbl.Schema) && tbl.Schema != "dbo") {#>
64         [Schema("<#=tbl.Schema#>")]
65 <#}#>
66     public partial class <#=tbl.ClassName#><#if (tbl.HasPK() && UseIdAsPK) { #> : IHasId<<#=tbl.PK.PropertyType#>><#}#> 
67     {
68 <# if (GenerateConstructor) { #>
69                 public <#=tbl.ClassName#>()
70                 {
71                 }
72
73 <# }
74 foreach(Column col in from c in tbl.Columns where !c.Ignore select c)
75 {
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) { #>
81         [AutoIncrement]
82 <# }  if (col.IsComputed) { #>
83         [Compute]        
84 <# }  if (col.IsNullable != true && col.IsAutoIncrement != true) { #>
85         [Required]
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) { #>
91                 [PrimaryKey]
92         public <#=col.ProperPropertyType#> <#=col.PropertyName#> { get; set;}
93 <# } #>
94 <# } #>
95     }
96 <#  manager.EndBlock(); #>
97 <#  }   #>
98 <#manager.StartFooter(); #>
99 }
100 #pragma warning restore 1591
101 <#manager.EndBlock(); #>
102 <#manager.Process(SplitIntoMultipleFiles); #>
103 <#  }   #>
104
105