公司框架实体类模板

<%@ CodeTemplate Language="C#" TargetLanguage="T-SQL" Debug="true" CompilerVersion="v3.5" Description="" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Optional="False" Category="Required" %>
<%@ Property Name="NameSpace" Optional="False" Type="System.String" Default="Beyondbit.App.Entity" Category="Style" Description="Object Namespace." %>
//----------------------------------------------------------------
// Copyright (C) 2012 上海互联网软件有限公司
// 版权所有.
// All rights reserved.
//
// 文件名: <%= SourceTable %>.cs
// 文件功能描述:
//
// 创建标识: <%= DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") %>
//
// 修改标识:
// 修改描述:
//----------------------------------------------------------------
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using Beyondbit.Framework.Biz.Entry;
using Beyondbit.Framework.Sor.Attributes;
<%--
SourceTable.Columns[i].ExtendedProperties[]
==CS_IsRowGuidCol
==CS_IsIdentity
==CS_IsComputed
==CS_IsDeterministic
==CS_IdentitySeed
==CS_IdentityIncrement
==CS_Default
==CS_ComputedDefinition
==CS_Collation
==CS_ObjectID
==CS_SystemType
==CS_UserType
==MS_Description
==CS_Description
--%>

namespace <%=NameSpace%> {
[Table("<%=SourceTable.Name%>", SorMappingType.ByAttributes)]
[Serializable]
public class <%=SourceTable.Name%> {
<%for (int i = 0; i < SourceTable.Columns.Count; ++i) {%>
///
///????????<%=SourceTable.Columns[i].ExtendedProperties["CS_SystemType"].Value%>
///
private <%=GetTypeName(SourceTable.Columns[i])%> _<%=SourceTable.Columns[i].Name%>;

<%
bool is_primary = SourceTable.Columns[i].IsPrimaryKeyMember;
bool is_identity = (SourceTable.Columns[i].ExtendedProperties["CS_IsIdentity"].Value.ToString() == "True");
%>

<%if (is_identity && is_primary) { %>
[Column("<%=SourceTable.Columns[i].Name%>", ColumnType.IdentityAndPrimaryKey)]
<%} else if (is_identity) {%>
[Column("<%=SourceTable.Columns[i].Name%>", ColumnType.Identity)]
<%} else if (is_primary) {%>
[Column("<%=SourceTable.Columns[i].Name%>", ColumnType.PrimaryKey)]
<%} else {%>
[Column("<%=SourceTable.Columns[i].Name%>", ColumnType.Normal)]
<%}%>
public <%=GetTypeName(SourceTable.Columns[i])%> <%=SourceTable.Columns[i].Name%> {
get {
return _<%=SourceTable.Columns[i].Name%>;
} set {
_<%=SourceTable.Columns[i].Name%> = value;
}
}

<%for(int j = 0; j < SourceTable.Columns[i].ExtendedProperties.Count; ++ j) {%>
<%--=SourceTable.Columns[i].ExtendedProperties[j].Name%>:<%=SourceTable.Columns[i].ExtendedProperties[j].Value--%>
<%}%>

<%}%>
}
}


<script runat="template">
public string GetTypeName(SchemaExplorer.ColumnSchema clmn) {
string result = "";
switch (clmn.DataType) {
case System.Data.DbType.AnsiString:
result = "string";
break;
case System.Data.DbType.Binary:
result = "byte[]";
break;
case System.Data.DbType.Int32:
result = "int";
break;
case System.Data.DbType.Byte:
result = "byte";
break;
case System.Data.DbType.Boolean:
result = "bool";
break;
case System.Data.DbType.Currency:
case System.Data.DbType.Single:
case System.Data.DbType.Decimal:
result = "float";
break;
case System.Data.DbType.Date:
case System.Data.DbType.DateTime:
case System.Data.DbType.DateTime2:
result = "DateTime";
break;
case System.Data.DbType.Double:
result = "double";
break;
case System.Data.DbType.Int64:
result = "long";
break;
case System.Data.DbType.String:
result = "string";
break;
default:
result = "string";
break;
}
return result;
}
</script>

原文地址:https://www.cnblogs.com/yuanxiaoping_21cn_com/p/2803914.html