用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
搞定!
下午试了一会,发现完全可行,其具体方式是
在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
搞定!
评论
# 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文件 http://blog.aspcool.com/tim/posts/159.aspx
2004-05-30 11:41 | 飞鹰
# re: 用Powerdesigner生成NHebernate的MAP文件
我是在0day下的,在www.sybase.com或者www.Quest.com(叫QDesigner)上应该可以下载的。2004-06-01 13:37 | wljcan