你的位置:首页 > ASP.net教程

[ASP.net教程]用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;    }   }  .elseprivate %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  /// 申请人ID151  /// <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  /// 企业ID183  /// <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 }