<%@ Template Language="C#" TargetLanguage="C#" Debug="True" Encoding="UTF-8" %> <%@ Assembly Src="..\..\Common\Model.cs" %> <%@ Assembly Src="..\..\Common\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="Namespace" Type="System.String" %> <%-- Safe类名 --%> <% string SafeClassName = Entity.ClassName.ToSafeName(); %> <%-- 描述 --%> <% string Description = Entity.Description; %> using System; using System.Collections.Generic; using Util; using <%= Entity.GetNamespace(Namespace,"Domain","Models") %>; namespace <%= string.Format("{0}.Test.Models.{1}",Namespace,Entity.TableSchema) %> { /// /// <%= Description %>测试数据 /// public partial class <%= SafeClassName %>Test { #region 测试数据1 <% foreach(Property p in Entity.Properties) { %> /// /// <%= p.Description %> /// <% if( p.IsPrimaryKey.SafeValue() ){ %> public static readonly <%= p.TypeName %> Id = "<%= Guid.NewGuid() %>"<%=Entity.GetToEntityConvert() %>; <%continue;} %> <% if( p.DataType == DbType.Guid ){ %> public static readonly <%= p.TypeName %> <%= p.PropertyName.ToSafeName() %> = "<%= Guid.NewGuid() %>".ToGuid(); <%continue;} %> <% if( p.DataType == DbType.Int32 ){ %> public static readonly <%= p.TypeName %> <%= p.PropertyName.ToSafeName() %> = 1; <%continue;} %> <% if( p.DataType == DbType.Decimal ){ %> public static readonly <%= p.TypeName %> <%= p.PropertyName.ToSafeName() %> = 1; <%continue;} %> <% if( p.DataType == DbType.DateTime ){ %> public static readonly <%= p.TypeName %> <%= p.PropertyName.ToSafeName() %> = "<%= DateTime.Now %>".ToDate(); <%continue;} %> <% if( p.DataType == DbType.Binary ){ %> public static readonly <%= p.TypeName %> <%= p.PropertyName.ToSafeName() %> = Util.Helpers.Convert.ToBytes( "1" ); <%continue;} %> <% if( p.ColumnName.ToLower() == "isdeleted" ){ %> public static readonly <%= p.TypeName %> <%= p.PropertyName.ToSafeName() %> = false; <%continue;} %> <% if( p.DataType == DbType.Boolean ){ %> public static readonly <%= p.TypeName %> <%= p.PropertyName.ToSafeName() %> = true; <%continue;} %> public static readonly <%= p.TypeName %> <%= p.PropertyName.ToSafeName() %> = "<%= p.PropertyName.ToSafeName() %>"; <% }%> #endregion #region 测试数据2 <% foreach(Property p in Entity.Properties) { %> /// /// <%= p.Description %> /// <% if( p.IsPrimaryKey.SafeValue() ){ %> public static readonly <%= p.TypeName %> Id2 = "<%= Guid.NewGuid() %>"<%=Entity.GetToEntityConvert() %>; <%continue;} %> <% if( p.DataType == DbType.Guid ){ %> public static readonly <%= p.TypeName %> <%= p.PropertyName.ToSafeName() %>2 = "<%= Guid.NewGuid() %>".ToGuid(); <%continue;} %> <% if( p.DataType == DbType.Int32 ){ %> public static readonly <%= p.TypeName %> <%= p.PropertyName.ToSafeName() %>2 = 2; <%continue;} %> <% if( p.DataType == DbType.Decimal ){ %> public static readonly <%= p.TypeName %> <%= p.PropertyName.ToSafeName() %>2 = 2; <%continue;} %> <% if( p.DataType == DbType.DateTime ){ %> public static readonly <%= p.TypeName %> <%= p.PropertyName.ToSafeName() %>2 = "<%= DateTime.Now.AddDays(1) %>".ToDate(); <%continue;} %> <% if( p.DataType == DbType.Binary ){ %> public static readonly <%= p.TypeName %> <%= p.PropertyName.ToSafeName() %>2 = Util.Helpers.Convert.ToBytes( "2" ); <%continue;} %> <% if( p.ColumnName.ToLower() == "isdeleted" ){ %> public static readonly <%= p.TypeName %> <%= p.PropertyName.ToSafeName() %> = false; <%continue;} %> <% if( p.DataType == DbType.Boolean ){ %> public static readonly <%= p.TypeName %> <%= p.PropertyName.ToSafeName() %>2 = true; <%continue;} %> public static readonly <%= p.TypeName %> <%= p.PropertyName.ToSafeName() %>2 = "<%= p.PropertyName.ToSafeName() %>2"; <% }%> #endregion #region Create(创建实体) /// /// 创建<%= Description %>实体 /// public static <%= SafeClassName %> Create(string id = "") { return new <%= SafeClassName %>( id<%=Entity.GetToEntityConvert() %> ) { <% foreach(Property p in Entity.Properties) { %> <% if( p.IsPrimaryKey.SafeValue() ) continue; %> <%= p.PropertyName.ToSafeName() %> = <%= p.PropertyName.ToSafeName() %>, <% }%> }; } /// /// 创建<%= Description %>实体2 /// /// <%= Description %>编号 public static <%= SafeClassName %> Create2( string id = "" ) { return new <%= SafeClassName %>( id<%=Entity.GetToEntityConvert() %> ) { <% foreach(Property p in Entity.Properties) { %> <% if( p.IsPrimaryKey.SafeValue() ) continue; %> <%= p.PropertyName.ToSafeName() %> = <%= p.PropertyName.ToSafeName() %>2, <% }%> }; } #endregion #region CreateList(创建列表) /// /// 创建列表 /// public static List<<%= SafeClassName %>> CreateList() { return new List<<%= SafeClassName %>>() { Create(), Create2() }; } #endregion } }