如果我的Db模式中有n个表,如果我想要遍历Db和中的所有表--和--为每个包含以下生成代码的表创建一个.cs文件:
public class TableName
{
private _tableName = "<%TableName%>" //This string will be generated by MyGeneration
// per each table
public string TableName {
get{ return _tableName; }
}如何编写我的模板?
发布于 2011-06-29 11:35:10
我以前没有使用过MyGeneration,但是您可以使用CodeGenerator轻松地做到这一点。模板看起来如下所示:
XSL模板
<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>结果
namespace [Your.Namespace]
{
public class [TableName1]
{
public string TableName { get { return "[TableName1]"; } }
}
//...other tables
public class [TableNameN]
{
public string TableName { get { return "[TableNameN]"; } }
}
}编辑:,您也可以让它在每个文件中输出一个表--听起来就像你想要的那样。
https://stackoverflow.com/questions/6519870
复制相似问题