Files

108 lines
4.0 KiB
Plaintext

<%@ Template Language="C#" TargetLanguage="C#" Debug="True" Encoding="UTF-8" %>
<%@ Register Name="TreeEntity" Template="TreeEntity.cst" MergeProperties="False" ExcludeProperties="" %>
<%@ 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; %>
<%-- 如果是树型实体,则调用子模板 --%>
<%
if( Entity.IsTreeEntity() ){
CodeTemplate template =new TreeEntity();
template.SetProperty("Namespace",Namespace);
template.SetProperty("Entity",Entity);
template.Render(this.Response);
return;
}
%>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Util;
using Util.Domains;
using Util.Domains.Auditing;
using Util.Domains.Tenants;
namespace <%= Entity.GetNamespace(Namespace,"Domain","Models") %> {
/// <summary>
/// <%= Description %>
/// </summary>
[DisplayName( "<%= Description %>" )]
public partial class <%= SafeClassName %> : <%= Entity.GetAggregateRootAndInterfaces() %> {
/// <summary>
/// 初始化<%= Description %>
/// </summary>
public <%= SafeClassName %>() : this( <%= Entity.GetKeyDefault() %> ) {
}
/// <summary>
/// 初始化<%= Description %>
/// </summary>
/// <param name="id"><%= Description %>标识</param>
public <%= SafeClassName %>( <%= Entity.GetKeyTypeString() %> id ) : base( id ) {
}
<% foreach(Property p in Entity.Properties) { %>
<% if( p.IsPrimaryKey.SafeValue() ) continue; %>
<% if( p.ColumnName == "Version" && p.DataType == DbType.Binary ) continue;%>
/// <summary>
/// <%= p.Description %>
/// </summary>
[DisplayName( "<%= p.Description %>" )]
<% if( p.HasValidate() ) {%>
<%= p.Validate() %>
<%}%>
public <%= p.TypeName %> <%= p.PropertyName.ToSafeName() %> { get; set; }
<% }%>
<% foreach(var r in Entity.Relationships) { %>
<% if(r.ThisCardinality != Cardinality.Many) { %>
/// <summary>
/// <%= Entity.GetOtherDescription( r.OtherEntity ) %>
/// </summary>
[ForeignKey( "<%=Entity.GetOtherIdProperty( r.OtherEntity )%>" )]
public <%= r.OtherEntity.ToSafeName() %> <%= r.ThisPropertyName.ToSafeName() %> { get; set; }
<% } %>
<% }%>
/// <summary>
/// 添加描述
/// </summary>
protected override void AddDescriptions() {
<% foreach(Property p in Entity.Properties) { %>
<% if( p.ColumnName == "Version" && p.DataType == DbType.Binary ) continue;%>
<% if( p.ColumnName == "IsDeleted" && p.DataType == DbType.Boolean ) continue;%>
<% if( p.IsPrimaryKey.Value ){ %>
AddDescription( t => t.Id );
<% continue;} %>
AddDescription( t => t.<%= p.PropertyName.ToSafeName() %> );
<% } %>
}
/// <summary>
/// 添加变更列表
/// </summary>
protected override void AddChanges( <%= SafeClassName %> other ) {
<% foreach(Property p in Entity.Properties) { %>
<% if( p.ColumnName == "Version" && p.DataType == DbType.Binary ) continue;%>
<% if( p.ColumnName == "IsDeleted" && p.DataType == DbType.Boolean ) continue;%>
<% if( p.IsPrimaryKey.Value ){ %>
AddChange( t => t.Id, other.Id );
<%continue; } %>
AddChange( t => t.<%= p.PropertyName.ToSafeName() %>, other.<%= p.PropertyName.ToSafeName() %> );
<% } %>
}
}
}