PowerDesigner调整SQL模板和C#实体模板

1. 自定义安装

PD一般只用来画ER图,查看生成的sql,只安装PDM模型即可,如果需要生成C#等语言的实体代码,则需要再勾选OOM模型,如果需要逆向生成数据库和版本控制,则需要勾选Repository

2. 生成SQL去除外键语句和Drop语句

3. 表字段设计窗口显示comment来编写注释

4. 生成C#实体代码模板

点击 tools - Generte Object-Oriented Model

在detail中convert names into codes,打勾则用名字作为实体类代码里的名称,不打勾就用表中code作为实体类代码里的名称。

这时可以看到language中有edit current object language和generage C# 2 code,
点击edit current object language中profile - Attribute - Templates 里有个definition文件。可以根据自己需要修改实体类模板

.if (%isValidAttribute%)

///<summary>
[%comment%\n]\
///</summary>
[%customAttributes%\n]\
.if (%Multiple% == false) and (%isIndexer% == false)
[%visibility% ][%flags% ]%dataType% %Code%[ = %InitialValue%]{get;set;}
.else
[%visibility% ][%flags% ]%dataType%[%arraySize%] %Code%[ = %InitialValue%]{get;set;}
.endif
.endif

如果不需要导航属性,需要删除以下模板

如果需要增加命名空间,在 classifier/Templates/sourceBody中修改如下:红色字体是你需要的命名空间

.// only toplevel classes are generated
.if (%ContainerClassifier% == null)
.// header and usings
[\
%usings%\n
]\
.// class/interface definition (global namespace)
.ifnot (%Package.namespace%)
namespace Tiandi.Web.Authority.Model
{
%definition%
}
.else
[\
%Package.comment%
]\
[\
%Package.customAttributes%
]\
namespace %Package.namespace%
{
%definition%
}
.endif
.endif

5. 枚举注释问题

养成规范,所有字段应加上注释,如果字段类型为枚举,频繁更新不方便,可参考实体枚举字段注释反向生成数据库注释sql

参考

  1. PowerDesigner使用教程
  2. PowerDesigner16.5物理数据表生成C#实体类Model
posted @ 2020-05-29 20:24  李锦成  阅读(551)  评论(1编辑  收藏  举报