本文介绍了如何在MyGeneration中实现此简单输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的Db模式中有n个表,并且我想遍历Db中的所有表创建一个 .cs 每个表的文件 ,其中将包含以下生成的代码:

If I have n tables in my Db schema and if I want to walk through all tables in my Db and create a .cs file for each table that will contain the below generated code:

public class TableName
{
  private _tableName = "<%TableName%>" //This string will be generated by MyGeneration 
                                  // per each table
  public string TableName {

         get{ return _tableName; }
}

应如何编写我的模板?

推荐答案

我以前没有与MyGeneration合作,但是您可以使用。模板看起来像这样:

I haven't worked with MyGeneration before but you can do this easily using CodeGenerator. The template would look something like this:

<xsl:stylesheet version="1.0" xmlns:P="http://Schemas.QuantumConceptsCorp.com/CodeGenerator/Project.xsd" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes">
    <xsl:output method="text" version="1.0" encoding="UTF-8" indent="no"/>

    <xsl:template match="P:Project">
        <xsl:text>
namespace  </xsl:text>
        <xsl:value-of select="@RootNamespace"/>
<xsl:text>.DataObjects
{</xsl:text>
        <xsl:for-each select="P:TableMappings/P:TableMapping[@Exclude='false']">
            <xsl:text>
    public partial class </xsl:text>
            <xsl:value-of select="@ClassName"/>
            <xsl:text>  
    {
        private string TableName  { get { return "</xsl:text>
            <xsl:value-of select="@ClassName"/>
            <xsl:text>"; } }
    }
    </xsl:text>
    </xsl:template>
</xsl:stylesheet>



结果



Result

namespace [Your.Namespace]
{
    public class [TableName1]
    {
        public string TableName { get { return "[TableName1]"; } }
    }

    //...other tables

    public class [TableNameN]
    {
        public string TableName { get { return "[TableNameN]"; } }
    }
}

编辑:您还可以让每个文件输出一个表-听起来就是您要的。

You can also have it output one table per file - it sounds like that's what you're after.

这篇关于如何在MyGeneration中实现此简单输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 09:24