zoukankan      html  css  js  c++  java
  • 代码生成器 CodeSmith 的使用(五)

    在上一篇的版本中,我们使数据库中的单个表 生成 PetaPoco 构架下的 ORM 映射,这次呢,要使数据库中的所有的表 生成 PetaPoco 构架下的 ORM 映射。

    首先来看完整的 Camel 规则模板:

    <p><%-- 
    Name:  Copyright © Sun 2013-2014 All rights reserved  
    Contact me:  <a target=_blank href="mailto:Sunnydayhu@163.com">Sunnydayhu@163.com</a>
    Author:  SpringFileld
    Description: 遍历数据库中所有的表,并映射成 PetaPoco类的 orm 
    DateTime: 2014-07-31
    --%></p><p><%@ 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" %>
    <%@ Assembly  Name="xftwl.Infrastructure" %>
    <%@ Import  Namespace="xftwl.Infrastructure" %></p><p><%foreach( var tb in SourceData.Tables){ %></p><p>    [TableName("<%=tb.Name %>")]
        <%foreach (var pk in tb.PrimaryKey.MemberColumns){ %>
        [PrimaryKey("<%= pk.Name%>")]
        <%} %>
        [ExplicitColumns]
        public partial class  <%=tb.Name %> 
          {
            <%foreach( var cl in tb.Columns) {%>  
             [Column]
             public <%=CSharpAlias[cl.SystemType.FullName]%> <%=StringUtil.ToCamelCase(cl.Name)%> { get; set; } 
            <%} %>
          }
            
        
    <%} %></p>


    Pascall 规则:

    <%-- 
    Name:  Copyright © Sun 2013-2014 All rights reserved  
    Contact me:  Sunnydayhu@163.com
    Author:  SpringFileld
    Description: 遍历数据库中所有的表,并映射成 PetaPoco类的 orm 
    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" %>
    <%@ Assembly  Name="xftwl.Infrastructure" %>
    <%@ Import  Namespace="xftwl.Infrastructure" %>
    
    <%foreach( var tb in SourceData.Tables){ %>
    
        [TableName("<%=tb.Name %>")]
        <%foreach (var pk in tb.PrimaryKey.MemberColumns){ %>
        [PrimaryKey("<%= pk.Name%>")]
        <%} %>
        [ExplicitColumns]
        public partial class  <%=tb.Name %> 
          {
            <%foreach( var cl in tb.Columns) {%>  
             [Column]
             public <%=CSharpAlias[cl.SystemType.FullName]%> <%=StringUtil.ToPascalCase(cl.Name)%> { get; set; } 
            <%} %>
          }
            
        
    <%} %>
    


    原生的:

    <%-- 
    Name:  Copyright © Sun 2013-2014 All rights reserved  
    Contact me:  Sunnydayhu@163.com
    Author:  SpringFileld
    Description: 遍历数据库中所有的表,并映射成 PetaPoco类的 orm 
    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" %>
    <%@ Assembly  Name="xftwl.Infrastructure" %>
    <%@ Import  Namespace="xftwl.Infrastructure" %>
    
    <%foreach( var tb in SourceData.Tables){ %>
    
        [TableName("<%=tb.Name %>")]
        <%foreach (var pk in tb.PrimaryKey.MemberColumns){ %>
        [PrimaryKey("<%= pk.Name%>")]
        <%} %>
        [ExplicitColumns]
        public partial class  <%=tb.Name %> 
          {
            <%foreach( var cl in tb.Columns) {%>  
             [Column]
             public <%=CSharpAlias[cl.SystemType.FullName]%> <%=cl.Name%> { get; set; } 
            <%} %>
          }
            
        
    <%} %>
    


     

  • 相关阅读:
    IR的评价指标之MRR
    双击启动tomcat中的startup.bat闪退原因及解决方法
    裁判文书网采集说明
    Java 验证码识别之多线程打码兔
    JVM 内存分配机制总结
    Java中多态的一些简单理解
    Java Callable并发编程模板
    JVM
    Command
    解决PHP下载文件时因时文件太大而报404错误
  • 原文地址:https://www.cnblogs.com/wisdo/p/4205353.html
Copyright © 2011-2022 走看看