<%@ Template Language="C#" TargetLanguage="C#" Debug="True" Encoding="UTF-8" %> <%@ Assembly Src="Model.cs" %> <%@ Assembly Src="Extensions.cs" %> <%@ Import Namespace="System.Collections.Generic" %> <%@ Import Namespace="System.Linq" %> <%@ Import Namespace="System.Text" %> <%@ Import Namespace="System.Text.RegularExpressions" %> <%@ Import Namespace="SchemaMapper" %> <%@ Property Name="Entity" Type="SchemaMapper.Entity" %> <%@ Property Name="EntityNamespace" Type="System.String" %> //------------------------------------------------------------------------------ // // This code was generated by a CodeSmith Template. // // DO NOT MODIFY contents of this file. Changes to this // file will be lost if the code is regenerated. // Author:Yubao Li // //------------------------------------------------------------------------------ using System; using System.Collections.Generic; using System.Text; namespace <%= EntityNamespace %> { /// /// <%= Entity.Description %> /// public partial class <%= Entity.ClassName.ToSafeName() %> { public <%= Entity.ClassName.ToSafeName() %>() { <% foreach(var p in Entity.Properties) { string type = p.SystemType.ToNullableType(p.IsNullable == true); if(type =="int" || type=="decimal") Response.WriteLine(" this."+p.PropertyName.ToSafeName()+"= 0;"); else if(type =="string") Response.WriteLine(" this."+p.PropertyName.ToSafeName()+"= string.Empty;"); else if(type.ToLower().Contains("datetime")) Response.WriteLine(" this."+p.PropertyName.ToSafeName()+"= DateTime.Now;"); } // foreach %> <% foreach(var r in Entity.Relationships.Where(e => e.ThisCardinality == Cardinality.Many)) { %> <%= r.ThisPropertyName.ToSafeName() %> = new List<<%= r.OtherEntity.ToSafeName() %>>(); <% } // foreach %> } <% foreach(var p in Entity.Properties) { %> /// /// <%=p.Description %> /// public <%= p.SystemType.ToNullableType(p.IsNullable == true) %> <%= p.PropertyName.ToSafeName() %> { get; set; } <% } // foreach %> <% foreach(var r in Entity.Relationships) { %> <% if(r.ThisCardinality == Cardinality.Many) { %> public virtual ICollection<<%= r.OtherEntity.ToSafeName() %>> <%= r.ThisPropertyName.ToSafeName() %> { get; set; } <% } else { %> public virtual <%= r.OtherEntity.ToSafeName() %> <%= r.ThisPropertyName.ToSafeName() %> { get; set; } <% } %> <% } // foreach %> } }