用Powerdesigner生成NHebernate的MAP文件

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

搞定!


      

posted on 2004-05-28 19:33 wljcan 阅读(5154) 评论(31)  编辑 收藏

评论

# re: 用Powerdesigner生成NHebernate的MAP文件

有没有办法扩展?做成一个插件的形式??
..不光Hibernate的配置文件可以搞定.别的也可以搞定~
2004-05-28 19:58 | hBifTs

# re: 用Powerdesigner生成NHebernate的MAP文件

这是在powerdesigner提供的一个配置文件上做的修改,如果想更加灵活,可以使用 ole的方式对其进行编程,在powerdesigner中提供了C#调用powerdesigner的例子。
我觉得这种方式已经很方便很灵活了,没有必要做插件,如果要生成其它的数据,只要修改这个配置文件就行。 甚至你自己就可以写一个这样的配置文件。
2004-05-28 20:20 | wljcan

# re: 用Powerdesigner生成NHebernate的MAP文件

不错啊 
2004-05-28 21:13 | progame

# re: 用Powerdesigner生成NHebernate的MAP文件 http://blog.aspcool.com/tim/posts/159.aspx
2004-05-30 11:41 | 飞鹰

# re: 用Powerdesigner生成NHebernate的MAP文件 使名扬

# re: 用Powerdesigner生成NHebernate的MAP文件

前段时间用的是9.5,刚刚升级到10,不过是试用版
2004-05-31 11:56 | wljcan

# re: 用Powerdesigner生成NHebernate的MAP文件

在哪儿可以下载到Powerdesigner 10?
2004-06-01 11:12 | 飞鹰

# re: 用Powerdesigner生成NHebernate的MAP文件

我是在0day下的,在www.sybase.com或者www.Quest.com(叫QDesigner)上应该可以下载的。
2004-06-01 13:37 | wljcan

# re: 用Powerdesigner生成NHebernate的MAP文件 如果是的话,中间的条件如何设置?

谢谢!

# re: 用Powerdesigner生成NHebernate的MAP文件

Powerdesigner 10已经下载,谢谢wljcan 。
2004-06-07 12:24 | 飞鹰

# re: 用Powerdesigner生成NHebernate的MAP文件 wljcan

相关文章: