mirror of
https://github.com/dotnetcore/Util.git
synced 2026-10-24 16:44:08 +08:00
142 lines
5.9 KiB
Plaintext
142 lines
5.9 KiB
Plaintext
<%@ 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) %> {
|
|
/// <summary>
|
|
/// <%= Description %>测试数据
|
|
/// </summary>
|
|
public partial class <%= SafeClassName %>Test {
|
|
|
|
#region 测试数据1
|
|
|
|
<% foreach(Property p in Entity.Properties) { %>
|
|
/// <summary>
|
|
/// <%= p.Description %>
|
|
/// </summary>
|
|
<% 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) { %>
|
|
/// <summary>
|
|
/// <%= p.Description %>
|
|
/// </summary>
|
|
<% 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(创建实体)
|
|
|
|
/// <summary>
|
|
/// 创建<%= Description %>实体
|
|
/// </summary>
|
|
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() %>,
|
|
<% }%>
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建<%= Description %>实体2
|
|
/// </summary>
|
|
/// <param name="id"><%= Description %>编号</param>
|
|
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(创建列表)
|
|
|
|
/// <summary>
|
|
/// 创建列表
|
|
/// </summary>
|
|
public static List<<%= SafeClassName %>> CreateList() {
|
|
return new List<<%= SafeClassName %>>() {
|
|
Create(),
|
|
Create2()
|
|
};
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |