zoukankan      html  css  js  c++  java
  • 用Powerdesigner生成NHebernate的MAP文件

    昨天通过修改Powerdesigner的配置文件实现特殊的C#代码生成要求后,今天突然想到:如果能够在Powerdesigner中直接生成Map文件,那就比较爽了。   

    下午试了一会,发现完全可行,其具体方式是
    在Profile\Classifier\Generated Files下添加一项,如hbm.xml,该项设置为
    文件名:%topContainerCode%.hbm.xml
    说明 :
                      .if (%isGenerated%)
                            .set_object(_usingContext,,new)
                           [\ %NHebernateHead%\n]\
                          %NHebernateBody% \n
                          %NHebernateFoot%
                       .endif    
    设置变量的值,如将 %NHebernateBody%设置为:
    <class name="%MyClassPathName%.%Parent.path%, %MyClassPathName%" table="%Parent.path%"> \n
          .foreach_item(Attributes)
            .if(%code%==%myPrimaryKey%)
       <id name="%code%" column="%code%" type="String">
        <generator class="assigned" />
       </id>  \n
          .endif
            .if (%dataType%=="string")
       <property name="%code%" column="%code%" type="String" /> \n
           .endif
           .if (%dataType%=="int")
       <property name="%code%" column="%code%" type="Int32" /> \n
           .endif
          .next
    </class>   
    (数据类型的转换部分可以自己加上)

    设置完成,在Project文件中添加对这些文件的引用。
    将Profile\BasePackage\Templates\VisualStudio.NET\ProjectSourceFiles设置为:
    .// Declare classifiers of the package
    .foreach_item(Classifiers,,,%IsShortcut%==false)
       .if (%IsSelected%) and (%isInner% == false)
    <File
        RelPath = "%sourceFilePath%"
        SubType = "Code"
        BuildAction = "Compile"
    />
    <File
        RelPath = "%Parent.path%\\%topContainerCode%.hbm.xml"
        BuildAction = "EmbeddedResource"
    />
       .endif(\n)
    .next
    .// Declare classifiers of the subpackages
    .foreach_item(Packages,,,%IsShortcut%==false)
       .if (%isAssembly% == false)
    %ProjectSourceFiles%
       .endif
    .next

    搞定!


          
  • 相关阅读:
    改造我们的学习:有钱不会花,抱着金库抓瞎
    (转)我奋斗了18年才和你坐在一起喝咖啡
    初学者要知道的十件事
    [转]C#图像处理 (各种旋转、改变大小、柔化、锐化、雾化、底片、浮雕、黑白、滤镜效果)
    C#调用系统的复制、移动、删除文件对话框
    SQLite数据类型
    jquery禁用dropdownlist中某一项
    C# winform无标题窗体随意移动
    注册.NET Framework
    jQuery同步/异步调用后台方法
  • 原文地址:https://www.cnblogs.com/wljcan/p/12093.html
Copyright © 2011-2022 走看看