<#@ include file="OrmLite.Core.ttinclude" #> <# // Settings ConnectionStringName = ""; // Uses last connection string in config if not specified Namespace = ""; ClassPrefix = ""; ClassSuffix = ""; bool SplitIntoMultipleFiles = false; // if true: Generates one file for every class bool MakeSingular = true; // if true: Changes the classname to singular if tablename is not singular bool UseIdAsPK = true; // if true: Changes the primary key property name to Id bool GenerateConstructor = false; // if true: Generates the default empty constructor bool UseSchemaAttribute = true; // if true: Adds explicit '[Schema]' attribute // Read schema var tables = LoadTables(MakeSingular); /* // Tweak Schema tables["tablename"].Ignore = true; // To ignore a table tables["tablename"].ClassName = "newname"; // To change the class name of a table tables["tablename"]["columnname"].Ignore = true; // To ignore a column tables["tablename"]["columnname"].PropertyName="newname"; // To change the property name of a column tables["tablename"]["columnname"].PropertyType="bool"; // To change the property type of a column */ // Generate output if (tables.Count>0) { #> <# if (string.IsNullOrEmpty(Namespace)) Namespace=ConnectionStringName; if (string.IsNullOrEmpty(Namespace)) Namespace="OrmLitePoco"; var manager = Manager.Create(Host, GenerationEnvironment); manager.StartHeader(); #>// // This file was generated by a T4 template. // Don't change it directly as your change would get overwritten. Instead, make changes // to the .tt file (i.e. the T4 template) and save it to regenerate this file. // Make sure the compiler doesn't complain about missing Xml comments #pragma warning disable 1591 using System; using System.Collections.Generic; using System.Linq; using System.Web; using ServiceStack.OrmLite; using ServiceStack.DataAnnotations; using ServiceStack.Model; namespace <#=Namespace #> { <#manager.EndBlock(); #> <# foreach(Table tbl in from t in tables where !t.Ignore select t) { manager.StartNewFile(tbl.Name + ".cs"); #> <# if (MakeSingular) {#> [Alias("<#=tbl.Name#>")] <#}#> <# if (UseSchemaAttribute && !string.IsNullOrEmpty(tbl.Schema) && tbl.Schema != "dbo") {#> [Schema("<#=tbl.Schema#>")] <#}#> public partial class <#=tbl.ClassName#><#if (tbl.HasPK() && UseIdAsPK) { #> : IHasId<<#=tbl.PK.PropertyType#>><#}#> { <# if (GenerateConstructor) { #> public <#=tbl.ClassName#>() { } <# } foreach(Column col in from c in tbl.Columns where !c.Ignore select c) { if ((col.Name!=col.PropertyName) || (col.IsPK && UseIdAsPK)) { #> [Alias("<#=col.Name#>")] <# } if (col.PropertyType == "string" && col.Size > 0) { #> [StringLength(<#=col.Size#>)] <# } if (col.IsAutoIncrement) { #> [AutoIncrement] <# } if (col.IsComputed) { #> [Compute] <# } if (col.IsNullable != true && col.IsAutoIncrement != true) { #> [Required] <# } if (!col.IsPK){#> public <#=col.ProperPropertyType#> <#=col.PropertyName#> { get; set;} <# } if (col.IsPK && UseIdAsPK) { #> public <#=col.ProperPropertyType#> Id { get; set;} <# } if (col.IsPK && !UseIdAsPK) { #> [PrimaryKey] public <#=col.ProperPropertyType#> <#=col.PropertyName#> { get; set;} <# } #> <# } #> } <# manager.EndBlock(); #> <# } #> <#manager.StartFooter(); #> } #pragma warning restore 1591 <#manager.EndBlock(); #> <#manager.Process(SplitIntoMultipleFiles); #> <# } #>