项目经理提供关于code-review的一些问题

1.deletion_blocksemp_type都是varchar类型,代码里面需要加上单引号,确保以后出现字母不会出错。  

 

 

2.SQL的拼装

如果你是调用者,怎样知道para长度的定义?需要注意parameter命名规则。至少在方法加上备注,自己以后也容易阅读。要不只有神仙才知道

在什么情况下使用ToString(),如果已经是string就不需要了。很多httpRequest[“parameter”].ToString(),如果非空倒无所谓,如果没这个parameter,直接toString()就不可以。

拼装遇到单引号怎么办?使用ConvertUtil.ToSqlText

什么情况下数据类型转换,如下图32行拼装 string时,转换int并不必要。

Method named, StopList=>named TerminatedList is better

 

拼装SQL的方法,建议使用@

 

当前拼装SQL的方法1

            StringBuilder sb = new StringBuilder();

            sb.Append("select aa.contract_name,bb.[type_id],cc.type_desc from CMS_Contract aa with(nolock) join CMS_V_ContractSubType bb with(nolock) on aa.contract_sub_type=bb.type_sub_id");

            sb.Append(" join CMS_V_ContractType cc with(nolock) on cc.[type_id]=bb.[type_id] where aa.contract_id=@contract_id and bb.[type_id] in (");

            sb.Append("select c.[type_id] from CMS_TargetOutlet a with(nolock) join CMS_Contract b with(nolock) on a.contract_id=b.contract_id");

            sb.Append(" join CMS_V_ContractSubType c with(nolock) on b.contract_sub_type=c.type_sub_id where a.outlet_no=@outlet_no and a.contract_id<>@contract_id2)");

当前拼装SQL的方法也有string sql, sql+=””;…

 

建议:

            StringBuilder sb = new StringBuilder();

            sb.Append(@"select aa.contract_name,bb.[type_id],cc.type_desc from CMS_Contract aa with(nolock) join CMS_V_ContractSubType bb with(nolock) on aa.contract_sub_type=bb.type_sub_id

join CMS_V_ContractType cc with(nolock) on cc.[type_id]=bb.[type_id] where aa.contract_id=@contract_id and bb.[type_id] in (

select c.[type_id] from CMS_TargetOutlet a with(nolock) join CMS_Contract b with(nolock) on a.contract_id=b.contract_id

join CMS_V_ContractSubType c with(nolock) on b.contract_sub_type=c.type_sub_id where a.outlet_no=@outlet_no and a.contract_id<>@contract_id2)");

 

 

3.判断有没有数据返回的方法

 

4. executeNonQuery在没有记录返回时,oReturn是不是null.

 

NonQuery应该返回的是结果集行数,肯定不会为空

  

5.封装的程序度

 

6.适当的添加with(nolock)。如上图

7.命名统一使用CMS

 

8.适当的使用VIEWSQL,代替在.net拼装SQL

 

9.使用CI CodeTable,建议添加VIEW

 

10.能一次DB查询完成

  

11.返回的数据类型,如果返回DataTable,需要调用者知道table的定义。换用entity可能会更好。

调用者也会简洁很多,把对数据层处理从UI剥离

 

posted @ 2011-03-28 17:12  peterlee  阅读(263)  评论(0)    收藏  举报