Drea Robot

PowerDesigner 创建数据库模型、自动生成模型类、自动生成Sql脚本

 一、保存工作空间

二、文件->新建模型

三、新建数据库表

四、修改数据库表名称

五、设置数据库表字段

六、工具->Generate Object-Oriented Model

打开详情页签,去掉“检查模型”和名称转换为编码

打开常规,选择你想要生成的语言,应用并确认

 

七、语言 > Edit Current Object Language > Profile > Attribute > Templates > definition

按自己的需求重写代码实体生成模板应用确认即可,比如我的C#模板:

.if (%isValidAttribute%)

///<summary>
/// [%Name%\n]
.if (%comment%)
[%comment%\n]
.endif
///</summary>

.if (%Multiple% == false) and (%isIndexer% == false)
[%visibility% ][%flags% ]%dataType% %Code%[ = %InitialValue%] { get; set; }

.else
[%visibility% ][%flags% ]%dataType%[%arraySize%] %Code%[ = %InitialValue%] { get; set; }

.endif
.endif

 

 

八、语言 > Edit Current Object Language > Profile > classifier > Templates > sourceBody

按自己的需求重写代码命名空间生成模板应用确认即可,比如我的C#模板:

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

 

  

 

九、语言->Generate C# Code->Generated Files

选择你需要代码的生成的模型

 

十、数据库->Change Current DBMS

选择你要生成的Sql格式

十一、数据库->生成数据库

确认生成即可

 

posted @ 2018-02-07 11:41  Rhyheart  阅读(683)  评论(0编辑  收藏  举报
Rhyheart