codesmith entity模板for enterprise library 5

<%@ 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
//
//
// create time:<%= 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%> {
[Serializable]
public class <%=SourceTable.Name%> {
<%for (int i = 0; i < SourceTable.Columns.Count; ++i) {%>
///
///database type:<%=SourceTable.Columns[i].ExtendedProperties["CS_SystemType"].Value%>
///
private <%=GetTypeString(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");
%>

public <%=GetTypeString(SourceTable.Columns[i])%> <%=SourceTable.Columns[i].Name%> {
get {
return _<%=SourceTable.Columns[i].Name%>;
} set {
_<%=SourceTable.Columns[i].Name%> = value;
}
}
<%}%>
}
}

<script runat="template">
public string GetTypeString(SchemaExplorer.ColumnSchema clmn) {
string type = clmn.DataType.ToString();
switch (type) {
case "AnsiString":
case "String":
type = "String";
break;
case "Int32":
type = "int";
break;
case "DateTime":
type = "DateTime";
break;
case "Double":
type = "double";
break;
case "Binary":
type = "byte[]";
break;
case "Boolean":
type = "bool";
break;
case "Decimal":
type = "decimal";
break;
case "Single":
type = "float";
break;
case "Currency":
type = "decimal";
break;
case "Xml":
type = "string";
break;
case "AnsiStringFixedLength":
type = "string";
break;
case "Float":
type = "float";
break;
case "Guid":
type = "string";
break;
case "Byte":
type = "byte";
break;

default:
//type = "String";
break;
}
return type;
}

</script>

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