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; } 
            <%} %>
          }
            
        
    <%} %>
    


     

  • 相关阅读:
    日志管理
    LAMP源码编译安装
    实现LAMP架构
    mariadb-server安装问题(Error: MariaDB-common conflicts with 1:mariadb-libs-5.5.60-1.el7_5.x86_64)
    MySQL之八---Mysql实现数据库主从复制、主主复制、级联复制、半同步复制及复制监控
    httpd-2.4源码编译
    HTTPD之三----HTTPS加密技术及重定向
    HTTPD之二---HTTPD服务详解——httpd的配置文件常见设置
    HTTPD之一---HTTPD服务基础理论
    MySQL的MHA实现高可用性
  • 原文地址:https://www.cnblogs.com/wisdo/p/4205353.html
Copyright © 2011-2022 走看看