CodeSmith如何生成实体类

时间:2021-10-17 19:38:35

CodeSmith如何生成实体类

这是模板,然后选择对应的表。就可以生成 了

<%--
Name: Database Table Properties
Author: Paul Welter
Description: Create a list of properties from a database table
--%>
<%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" Description="Create a list of properties from database table." %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="Table that the object is based on." %>
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %> [Table("<%=SourceTable.Name%>")]
public class <%= StringUtil.ToPascalCase(SourceTable.Name) %>
{
<% foreach (ColumnSchema column in this.SourceTable.Columns) { %>
private <%= CSharpAlias[column.SystemType.FullName] %> _<%= StringUtil.ToCamelCase(column.Name) %>;
[Column("<%=column.Name%>")]
public <%= CSharpAlias[column.SystemType.FullName] %> <%= StringUtil.ToPascalCase(column.Name) %>
{
get { return _<%= StringUtil.ToCamelCase(column.Name) %>; }
set { _<%= StringUtil.ToCamelCase(column.Name) %> = value; }
} <% } %> }