用户登录
用户注册

分享至

codesmith调用实体

  • 作者: 黄小花-
  • 来源: 51数据库
  • 2020-09-22

一、用CodeSmith自带模版生成实体类


选中模版(businessobject.cst),右键执行(Execute),然后选择保存目录、数据库、表,最后生成(Generate)。


1、新建一个C#模版,导包
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
//声明SourceTable
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Default="" Optional="False" Category="Context" Description="源表" %>
2、设置SourceTable
先执行
Tools-Build
然后在属性杂项一栏中设置SourceTable
选择数据库,再选择表。
3、写封装类
namespace Train{
public class Train
{
//这里的内容为私有字段和公开属性。
<%foreach(ColumnSchema column in this.SourceTable.Columns)%>
<%{%>
private <%=column.SystemType%> <%=column.Name%>;
<%}%>
<%foreach(ColumnSchema column in this.SourceTable.Columns)%>
<%{%>
public <%=column.SystemType%> <%=column.Name%>
{
get{return <%=column.Name%>;}
set{<%=column.Name%>=value;}
}
<%}%>
}
}
4、执行Tools-Run 保存
补充:
添加数据库方法
在左边SchemaExplorer中选第二项
ADD添加
Name:Train
ProviderType:sqlSchemaProvider
ConnectionString:server=.;database=Train;uid=sa;pwd="1234";





這不必要圖 如果你還看不懂、、、、

软件
前端设计
程序设计
Java相关