<%@ CodeTemplate Language="C#" TargetLanguage="C#" ResponseEncoding="UTF-8" Src="" Inherits="OutputFileCodeTemplate" Debug="False" Description="The following template will generate a default ASP.Net code behind." %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="Table that the object is based on." %>
<%@ Property Name="Namespace" Type="System.String" Category="Context" Default="WDBuyNET.Entity" Description="Namespace that class belongs to." %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Assembly Name="System.Data" %>
<%@ Assembly Name="System.Net" %>
<%@ Import Namespace="SchemaExplorer" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Net" %>
<%@ Assembly Name="CodeSmith.BaseTemplates" %>
<%@ Import Namespace="CodeSmith.BaseTemplates" %>
<%@ Assembly Name="CodeSmith.CustomProperties" %>
<%@ Import Namespace="CodeSmith.CustomProperties" %>
<%
this.OutputFile = "D:\\work\\0802\\temp\\"+SourceTable.Name+".cs";
%>
//------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by CodeSmith Template.
//
// Creater: 作者
// Date: <%= DateTime.Now.ToShortDateString() %>
// Time: <%= DateTime.Now.ToShortTimeString() %>
// Version: 4.0.0.0
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using WDBuyNET.DMSFrame.DMSLinq;
using WDBuyNET.DMSFrame.DMSLinq.Attributes;
/// <summary>
///
/// </summary>
namespace <%= Namespace.Trim()==""?"WDBuyNET.Entity.DBEntity":Namespace %>
{
/// <summary>
/// Modal class: <%= GetClassName(SourceTable) %>.
/// </summary>
[Serializable]
[TableMapping(Name = "<%= GetClassName(SourceTable) %>", PrimaryKey = "<%= GetPrimaryKeyName(SourceTable) %>",DefaultOrderBy=" <%= GetPrimaryKeyName(SourceTable) %> Desc")]
public class <%= GetClassName(SourceTable) %> : BaseEntity
{
#region Private Properties
<% foreach (ColumnSchema column in SourceTable.Columns) { %>
<%= GetMemberVariableDeclarationStatement(column) %>//<%= column.ExtendedProperties["CS_Description"].Value.ToString().Replace("\r\n", ";").Replace("\n", ";") %>
<% } %>
#endregion
#region Public Properties
<% for (int i = 0; i < SourceTable.PrimaryKey.MemberColumns.Count; i++) { %>
<% ColumnSchema column = SourceTable.PrimaryKey.MemberColumns[i]; %>
/// <summary>
/// <%= column.ExtendedProperties["CS_Description"].Value.ToString().Replace("\r\n", ";").Replace("\n", ";") %>.
/// </summary>
[ColumnMapping(Name = "<%= GetPropertyName(column) %>"<% if ((bool)column.ExtendedProperties["CS_IsIdentity"].Value) { %>,AutoIncrement = true<% } %>)]
public <%= GetCSharpVariableType(column) == "string" ? GetCSharpVariableType(column) : GetCSharpVariableType(column) + "?" %> <%= GetPropertyName(column) %>
{
get
{
return <%= GetMemberVariableName(column) %>;
}
set
{
object _oldvalue = <%= GetMemberVariableName(column) %>;
<% if (column.SystemType == typeof(string) && column.NativeType != "text") { %>
<% if (column.Size>0) { %>
<%= GetMemberVariableName(column) %> = value.SubStr(<%=column.Size %>);
<% } else { %>
<%= GetMemberVariableName(column) %> = value;
<% } %>
<% } else { %>
<%= GetMemberVariableName(column) %> = value;
<% } %>
if ((value == null) || (!value.Equals(_oldvalue)))
{
this.OnPropertyChanged("<%= GetPropertyName(column) %>", _oldvalue, <%= GetMemberVariableName(column) %>);
<% if (!(bool)column.ExtendedProperties["CS_IsIdentity"].Value) { %>
this.OnMappingPropertyChanged("<%= GetPropertyName(column) %>", _oldvalue, <%= GetMemberVariableName(column) %>);
<% } %>
}
}
}
<% }%>
<% for (int i = 0; i < SourceTable.NonPrimaryKeyColumns.Count; i++) { %>
<% ColumnSchema column = SourceTable.NonPrimaryKeyColumns[i]; %>
/// <summary>
/// <%= column.ExtendedProperties["CS_Description"].Value.ToString().Replace("\r\n", ";").Replace("\n", ";") %>.
/// </summary>
[ColumnMapping(Name = "<%= GetPropertyName(column) %>"<% if ((bool)column.ExtendedProperties["CS_IsIdentity"].Value) { %>,AutoIncrement = true<% } %>)]
<% if (column.IsForeignKeyMember) { %>
public <%= GetClassName(GetForeignKeyTable(column)) %> <%= GetClassName(GetForeignKeyTable(column)) %>
{
get
{
return _<%= GetCamelCaseName(GetClassName(GetForeignKeyTable(column))) %>;
}
set
{
_<%= GetCamelCaseName(GetClassName(GetForeignKeyTable(column))) %> = value;
}
}
<% } else { %>
<% string strColLength = GetColLengthString(column); %>
public <%= GetCSharpVariableType(column) == "string" ? GetCSharpVariableType(column) : GetCSharpVariableType(column) + "?" %> <%= GetPropertyName(column) %>
{
get
{
return <%= GetMemberVariableName(column) %>;
}
set
{
object _oldvalue = <%= GetMemberVariableName(column) %>;
<% if (column.SystemType == typeof(string) && column.NativeType != "text") { %>
<% if (column.Size>0) { %>
<% if (column.Name.ToLower().IndexOf("imgname")>=0 || column.Name.ToLower().IndexOf("logo")>=0 || column.Name.ToLower().IndexOf("productimg")>=0 || column.Name.ToLower().IndexOf("image")>= 0) { %>
<%= GetMemberVariableName(column) %> = value;
<% }else { %>
<%= GetMemberVariableName(column) %> = value.SubStr(<%=column.Size %>);
<% }} else { %>
<%= GetMemberVariableName(column) %> = value;
<% } %>
<% } else { %>
<%= GetMemberVariableName(column) %> = value;
<% } %>
if ((value == null) || (!value.Equals(_oldvalue)))
{
this.OnPropertyChanged("<%= GetPropertyName(column) %>", _oldvalue, <%= GetMemberVariableName(column) %>);
<% if (!(bool)column.ExtendedProperties["CS_IsIdentity"].Value) { %>
this.OnMappingPropertyChanged("<%= GetPropertyName(column) %>", _oldvalue, <%= GetMemberVariableName(column) %>);
<% } %>
}
}
}
<% } %>
<% if (i < SourceTable.NonPrimaryKeyColumns.Count - 1) Response.Write("\r\n"); %>
<% } %>
#endregion
}
}
<script runat="template">
<!-- #include file="WDBuyNETGen.inc" -->
[FileDialog(FileDialogType.Save, Title="选择文件输出目录", Filter="Query Files (*.cs)|*.cs|All Files (*.*)|*.*", DefaultExtension=".cs")]
public override string OutputFile
{
get {return base.OutputFile;}
set {base.OutputFile = value;}
}
private string GetColLengthString(ColumnSchema column)
{
string strRet = "";
if (column.DataType == DbType.AnsiString || column.DataType == DbType.AnsiStringFixedLength ||
column.DataType == DbType.String || column.DataType == DbType.StringFixedLength ||
column.DataType == DbType.Binary)
{
strRet += ", Length=" + column.Size.ToString();
}
return strRet;
}
</script>
CodeSmith模板下载:http://www.cnblogs.com/hongjiumu/CodeTools(CodeSmith工具包).rar