mirror of
https://github.com/dotnetcore/Util.git
synced 2026-10-29 03:26:31 +08:00
101 lines
3.9 KiB
Plaintext
101 lines
3.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 System.ComponentModel;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using Util;
|
|
using Util.Domains;
|
|
using Util.Domains.Trees;
|
|
using Util.Domains.Auditing;
|
|
using Util.Domains.Tenants;
|
|
|
|
namespace <%= Entity.GetNamespace(Namespace,"Domain","Models") %> {
|
|
/// <summary>
|
|
/// <%= Description %>
|
|
/// </summary>
|
|
[Description( "<%= Description %>" )]
|
|
public partial class <%= SafeClassName %> : <%= Entity.GetTreeEntityAndInterfaces() %> {
|
|
/// <summary>
|
|
/// 初始化<%= Description %>
|
|
/// </summary>
|
|
public <%= SafeClassName %>()
|
|
: this( <%= Entity.GetKeyDefault() %>, "", 0 ) {
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化<%= Description %>
|
|
/// </summary>
|
|
/// <param name="id"><%= Description %>标识</param>
|
|
/// <param name="path">路径</param>
|
|
/// <param name="level">层级</param>
|
|
public <%= SafeClassName %>( <%= Entity.GetKeyTypeString() %> id, string path, int level )
|
|
: base( id, path, level ) {
|
|
}
|
|
|
|
<% foreach(Property p in Entity.Properties) { %>
|
|
<% if( p.IsPrimaryKey.SafeValue() ) continue; %>
|
|
<% if( p.ColumnName == "Version" && p.DataType == DbType.Binary ) continue;%>
|
|
<% if( Entity.IgnoreTreeEntityProperty(p) ) continue;%>
|
|
/// <summary>
|
|
/// <%= p.Description %>
|
|
/// </summary>
|
|
<% 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() %> );
|
|
<% } %>
|
|
}
|
|
}
|
|
} |