转自 http://www.java123.net/546230-1.html ,模板已修改成自己的
1.打开 Object Language Properties
菜单位置:Language → Edit Current Object Language
在 C# 2::ProfileClassifierGenerated Files ,创建一个 entity.xml 文件。
Name: entity.xml
FileName:%topContainerCode%.xml
Encoding: utf-8
Comment:
.if (%isGenerated%)
.set_object(_usingContext,,new)
[ %NHebernateHead% ]
%NHebernateBody%
%NHebernateFoot%
.endif
%NHebernateBody%
2.设置%NHebernateBody%模板的内容
在 C# 2::ProfileClassifierTemplates ,新建一个模板 NHebernateBody
<entity name="%Code%" remarks="%Name%" primarykey="id" >
.foreach_item(Attributes)
<field name="%Code%" type="%dataType%" remarks="%Name%" isnull="false"></field>
.next
</entity>
3.配置输出NHibernate的xml文件
在 C# 2::ProfileBasePackageTemplatesVisual Studio ,将模板修改为:
.// Declare classifiers of the package
.foreach_item(Classifiers,,,%IsShortcut%==false)
.if (%IsSelected%) and (%isInner% == false)
<File
RelPath = "%sourceFilePath%"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "%sourceFilePath%\%topContainerCode%.xml"
BuildAction = "EmbeddedResource"
/>
.endif(
)
.next
.// Declare classifiers of the subpackages
.foreach_item(Packages,,,%IsShortcut%==false)
.if (%isAssembly% == false)
%ProjectSourceFiles%
.endif
.next
NHibernate的xml配置完成。
最后,一起导出实体和NHibernate的.xml文件
菜单位置:Language → Generate C# 2 Code