代码生成器 CodeSmith 的使用(四)
来源:互联网 发布:mac terminal 有趣 编辑:程序博客网 时间:2024/04/30 04:10
在上一篇的版本中,我们生成了数据库中的字段,使生成的属性更加简洁,可读性也提高了很多,但都是钍对一个数据库的单个表,如果要将数据库中的所有的表都生成相应的类,表中的字段也都生成属性,运行一次就可以将所有的表中的字段都生成属性。这样不仅提高了代码的生产效率,同时,为我们省去了很多枯燥乏味的工作,把主要的精力集中在业务的处理上。
接下来就是要生成一个数据库中所有表中的所有的字段属性。同样的,生成后的规则也有三种, Camel规则, Pascal规则,和原生的
首先来看完整的 Camel 规则模板:
<%--Name: Copyright © Sun 2013-2014 All rights reservedContact me: Sunnydayhu@163.comAuthor: SpringFileldDescription: 遍历数据库中所有的表,并映射成 类的属性 Camel 规则DateTime: 2014-07-31--%><%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" Description="Create a list of properties from database table." %><%@ Property Name="SourceData" Type="SchemaExplorer.DatabaseSchema" 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" %><%foreach( var tb in SourceData.Tables){ %> public partial class <%=StringUtil.ToCamelCase(tb.Name) %> { <%foreach( var cl in tb.Columns) {%> public <%=CSharpAlias[cl.SystemType.FullName]%> <%=StringUtil.ToCamelCase(cl.Name)%> { get; set; } <%} %> }<%} %>
生成的效果如下:
public partial class accCardAccount { public int id { get; set; } public System.DateTime dateCreate { get; set; } public string card { get; set; } public decimal balance { get; set; } public decimal interest { get; set; } public decimal interestRates { get; set; } public string remark { get; set; } } public partial class accCardComhistory { public int id { get; set; } public System.DateTime dateCreate { get; set; } public string cardNo { get; set; } public decimal bonus { get; set; } public decimal welfare { get; set; } public string rechargeCardNo { get; set; } public decimal rechargeMoney { get; set; } }
生成的效果如下:
public partial class AccCardAccount { public int Id { get; set; } public System.DateTime DateCreate { get; set; } public string Card { get; set; } public decimal Balance { get; set; } public decimal Interest { get; set; } public decimal InterestRates { get; set; } public string Remark { get; set; } } public partial class AccCardComhistory { public int Id { get; set; } public System.DateTime DateCreate { get; set; } public string CardNo { get; set; } public decimal Bonus { get; set; } public decimal Welfare { get; set; } public string RechargeCardNo { get; set; } public decimal RechargeMoney { get; set; } }
原生的:
<%--Name: Copyright © Sun 2013-2014 All rights reservedContact me: Sunnydayhu@163.comAuthor: SpringFileldDescription: 遍历数据库中所有的表,并映射成类的属性 PrimitiveDateTime: 2014-07-31--%><%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" Description="Create a list of properties from database table." %><%@ Property Name="SourceData" Type="SchemaExplorer.DatabaseSchema" 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" %><%foreach( var tb in SourceData.Tables){ %> public partial class <%=tb.Name %> { <%foreach( var cl in tb.Columns) {%> public <%=CSharpAlias[cl.SystemType.FullName]%> <%=cl.Name%> { get; set; } <%} %> }<%} %>
生成的效果:
public partial class acc_card_account { public int Id { get; set; } public System.DateTime DateCreate { get; set; } public string Card { get; set; } public decimal Balance { get; set; } public decimal Interest { get; set; } public decimal InterestRates { get; set; } public string Remark { get; set; } } public partial class acc_card_comhistory { public int Id { get; set; } public System.DateTime DateCreate { get; set; } public string CardNo { get; set; } public decimal Bonus { get; set; } public decimal Welfare { get; set; } public string RechargeCardNo { get; set; } public decimal RechargeMoney { get; set; } }
0 0
- 代码生成器 CodeSmith 的使用(四)
- 代码生成器 CodeSmith 的使用(一)
- 代码生成器 CodeSmith 的使用(二)
- 代码生成器 CodeSmith 的使用(三)
- 代码生成器 CodeSmith 的使用(五)
- 代码生成器 CodeSmith 的使用(六)
- 用CodeSmith 代码生成器 生成代码
- James写的CodeSmith模板(四)
- 使用CodeSmith 生成代码
- CodeSmith基础(四)
- CodeSmith基础(四)
- CodeSmith基础(四)
- CodeSmith基础(四)
- 脚本是个好东西,要搞出一个类似CodeSmith的代码生成器真的很EASY
- Codematic2(动软.Net代码生成器)与CodeSmith区别与联系
- PP代码生成器(四) 使用解决方案生成代码
- codeSmith的使用教程
- 使用 CodeSmith 的心得体会
- C语言打印菱形、金字塔
- 关于终端任务栏导致的窗口上浮问题
- readb(), readw(), readl(),writeb(), writew(), writel() 宏函数
- Eclipse “cannot be resolved to a type” error
- 建立ARM平台上的交叉调试器gdb和gdbserver
- 代码生成器 CodeSmith 的使用(四)
- gsoap namespace 修改
- Java UDP网络编程 - 最简单示例
- swift_重载和自定义运算符
- Fuel PHP框架中的分页实现
- JQuery实现页面刷新后菜单保留鼠标点击addclass的样式
- 实现线性表的遍历查询插入删除合并
- iOS模块开发—登陆注册
- 利用coredump定位出错的代码行