使用powerDesigner反向工程生成Entity

由於業務需要將數據庫裏面的表導出來生成pdm數據模型,於是查找了一下方法,總結步驟如下:

1、打開plSQL,上方工具欄tools->ExportUser Objects

 

2、選中你需要導出的表,選擇文件位置,導出SQL文件

 3、打開powerDesigner,新建模型

4、選擇Model types ->Physical Data Modal ->Physical Diagram,自行修改文件名,保存

 

5、打開File->Reverse Engineer->Database

6、看到如下彈窗,點擊確定

7、 添加SQL文件,點擊運行

8、完成

9、 如果數據庫中的表有字段備註,希望直接用備註作爲名稱,可以打開Tools->Execute Comments->Edit/Run Script

10、 複製以下代碼到編輯器中:

 Option Explicit

ValidationMode = True

InteractiveMode = im_Batch

Dim mdl ' the current model

' get the current active model

Set mdl = ActiveModel

If (mdl Is Nothing) Then

MsgBox "There is no current Model"

ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then

MsgBox "The current model is not an Physical Data model."

Else

ProcessFolder mdl

End If

' This routine copy name into code for each table, each column and each view

' of the current folder

Private sub ProcessFolder(folder)

Dim Tab 'running table

for each Tab in folder.tables

if not tab.isShortcut then

if tab.comment ="" then

else

tab.name=tab.comment

on error resume next

end if

Dim col ' running column

for each col in tab.columns

if col.comment="" then

col.name=col.name

else

col.name=col.comment

on error resume next

end if

next

end if

next

Dim view 'running view

for each view in folder.Views

if not view.isShortcut then

if view.comment="" then

view.name=view.name

else

view.name=view.comment

on error resume next

end if

end if

next

' go into the sub-packages

Dim f ' running folder

For Each f In folder.Packages

if not f.IsShortcut then

ProcessFolder f

end if

Next

end sub

11、運行,搞定

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章