一、用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";这不必要图 如果你还看不懂、、、、
1+1
Photoshop|
Dreamweaver|
SVG|
WebGL|
Visual Studio|
PowerDesigner|
Eclipse|
Git|
Apache Ant|
Atom|
Composer|
CodeSmith|
Flex|
Gradle|
Maven|
Sublime Text3|
SVN|
Tableau|
Vim|
Chrome开发者工具|
OpenGL|
Unity|
Direct3D|
用户登录
还没有账号?立即注册
用户注册
投稿取消
文章分类: |
|
还能输入300字
上传中....