用PowerDesigner將SQL語句生成實體類


1.首先打開PowerDesigner,點擊左上角“File”—>"Reverse Engineer"—>"Database..."

2.選擇數據庫,導入sql腳本,生成物理模型。‘

3.選擇Tools-Generate Object-Oriented Model,選擇要生成哪種語言。點擊configure model options可以調整生成格式。

我將Name選擇為UPPERCASE,Code選擇lowercase

4.確定,新生成了model,現在選擇Language-Edit Current Object Language,修改Profile/Attribute/Templates/definition為需要的形式

我的代碼為

.if (%isValidAttribute%)
/// <summary>   
[%comment%\n]\
/// <summary>
[%customAttributes%\n]\   
[%oidDocTag%\n]\
 .if (%Multiple% == 1) and (%isIndexer% == false)
private %dataType% _%fieldCode%[ = %InitialValue%];   
   [%visibility% ][%flags% ]%dataType% %Name%   
   {   
    get     
    {   
     return _%fieldCode%;   
    }   
    set   
    {   
     _%fieldCode% = value;   
    }   
   }   
 .else
private %dataType%[%arraySize%] _%fieldCode%[ = %InitialValue%];   
   [%visibility% ][%flags% ]%dataType%[%arraySize%] %Name%   
   {   
    get     
    {   
     return _%fieldCode%;   
    }   
    set   
    {   
     _%fieldCode% = value;   
    }     
}   
 .endif   
.endif

5.選擇language-generate xx code ,選擇一個目錄,實體類代碼就生成好了。我生成的格式如下

  1 public class SH
  2 {
  3    /// <summary>   
  4    /// 審核狀態:0未審核1審核通過2審核不通過
  5    /// <summary>
  6       
  7    private decimal _state;   
  8       public decimal STATE   
  9       {   
 10        get     
 11        {   
 12         return _state;   
 13        }   
 14        set   
 15        {   
 16         _state = value;   
 17        }     
 18    }
 19    /// <summary>   
 20    /// 審核意見
 21    /// <summary>
 22       
 23    private string _shyj;   
 24       public string SHYJ   
 25       {   
 26        get     
 27        {   
 28         return _shyj;   
 29        }   
 30        set   
 31        {   
 32         _shyj = value;   
 33        }     
 34    }
 35    /// <summary>   
 36    /// 審核時間
 37    /// <summary>
 38       
 39    private DateTime _shsj;   
 40       public DateTime SHSJ   
 41       {   
 42        get     
 43        {   
 44         return _shsj;   
 45        }   
 46        set   
 47        {   
 48         _shsj = value;   
 49        }     
 50    }
 51    /// <summary>   
 52    /// 審核人姓名
 53    /// <summary>
 54       
 55    private string _shrname;   
 56       public string SHRNAME   
 57       {   
 58        get     
 59        {   
 60         return _shrname;   
 61        }   
 62        set   
 63        {   
 64         _shrname = value;   
 65        }     
 66    }
 67    /// <summary>   
 68    /// 審核人ID
 69    /// <summary>
 70       
 71    private string _shrid;   
 72       public string SHRID   
 73       {   
 74        get     
 75        {   
 76         return _shrid;   
 77        }   
 78        set   
 79        {   
 80         _shrid = value;   
 81        }     
 82    }
 83   
 84    /// <summary>   
 85    /// 申請原因
 86    /// <summary>
 87       
 88    private string _sqyy;   
 89       public string SQYY   
 90       {   
 91        get     
 92        {   
 93         return _sqyy;   
 94        }   
 95        set   
 96        {   
 97         _sqyy = value;   
 98        }     
 99    }
100  
101    /// <summary>   
102    /// 申請時間
103    /// <summary>
104       
105    private DateTime _sqtime;   
106       public DateTime SQTIME   
107       {   
108        get     
109        {   
110         return _sqtime;   
111        }   
112        set   
113        {   
114         _sqtime = value;   
115        }     
116    }
117    /// <summary>   
118    /// 申請人手機號
119    /// <summary>
120       
121    private string _mobile;   
122       public string MOBILE   
123       {   
124        get     
125        {   
126         return _mobile;   
127        }   
128        set   
129        {   
130         _mobile = value;   
131        }     
132    }
133    /// <summary>   
134    /// 申請人姓名
135    /// <summary>
136       
137    private string _username;   
138       public string USERNAME   
139       {   
140        get     
141        {   
142         return _username;   
143        }   
144        set   
145        {   
146         _username = value;   
147        }     
148    }
149    /// <summary>   
150    /// 申請人ID
151    /// <summary>
152       
153    private string _userid;   
154       public string USERID   
155       {   
156        get     
157        {   
158         return _userid;   
159        }   
160        set   
161        {   
162         _userid = value;   
163        }     
164    }
165    /// <summary>   
166    /// 企業名稱
167    /// <summary>
168       
169    private string _cpname;   
170       public string CPNAME   
171       {   
172        get     
173        {   
174         return _cpname;   
175        }   
176        set   
177        {   
178         _cpname = value;   
179        }     
180    }
181    /// <summary>   
182    /// 企業ID
183    /// <summary>
184       
185    private string _cpid;   
186       public string CPID   
187       {   
188        get     
189        {   
190         return _cpid;   
191        }   
192        set   
193        {   
194         _cpid = value;   
195        }     
196    }
197    /// <summary>   
198    /// 唯一標識
199    /// <summary>
200       
201    private string _id;   
202       public string ID   
203       {   
204        get     
205        {   
206         return _id;   
207        }   
208        set   
209        {   
210         _id = value;   
211        }     
212    }
213 
214 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM