在上一篇的版本中,我们使数据库中的单个表 生成 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; } 
        <%} %>
      }
        
    
<%} %>


 

 

posted on 2015-01-27 15:02  wisdo  阅读(202)  评论(0编辑  收藏  举报