在三层结构中,读取信息后怎么给多个实体类赋值比较好?
查询时,当读取到信息后给实体类赋值,一般的是这样进行的:
model.CGDD_GUID = new Guid(reader["CGDD_GUID"].ToString());
model.CGDD_ID = Utility.Transforms.Str2Int(reader["CGDD_ID"].ToString());
model.CGDD_BZ = reader["CGDD_BZ"].ToString();
model.CGDD_CK_GUID = new Guid(reader["CGDD_CK_GUID"].ToString());
model.CGDD_DDLX_ID = new Guid(reader["CGDD_DDLX_ID"].ToString());
model.CGDD_DJBH = reader["CGDD_DJBH"].ToString();
model.CGDD_FGUID = new Guid(reader["CGDD_FGUID"].ToString());
model.CGDD_GYS_GUID = new Guid(reader["CGDD_GYS_GUID"].ToString());
model.CGDD_JE = !string.IsNullOrEmpty(reader["CGDD_JE"].ToString()) ? Utility.Transforms.Str2Int(reader["CGDD_JE"].ToString()) : decimalNull;
model.CGDD_LYDH = reader["CGDD_LYDH"].ToString();
model.CGDD_RQ = !string.IsNullOrEmpty(reader["CGDD_RQ"].ToString()) ? Utility.Transforms.Str2DateTime(reader["CGDD_RQ"].ToString()) : timeNull;
model.CGDD_SL = !string.IsNullOrEmpty(reader["CGDD_SL"].ToString()) ? Utility.Transforms.Str2Int(reader["CGDD_SL"].ToString()) : decimalNull;
model.CGDD_YDJH = reader["CGDD_YDJH"].ToString();
model.CGDD_DHRQ = !string.IsNullOrEmpty(reader["CGDD_DHRQ"].ToString()) ? Utility.Transforms.Str2DateTime(reader["CGDD_DHRQ"].ToString()) : timeNull;
model.CGDD_FHRQ = !string.IsNullOrEmpty(reader["CGDD_FHRQ"].ToString()) ? Utility.Transforms.Str2DateTime(reader["CGDD_FHRQ"].ToString()) : timeNull;
model.CGDD_HY_GUID = new Guid(reader["CGDD_HY_GUID"].ToString());
model.CGDD_JGXD = reader["CGDD_JGXD"].ToString();
model.CGDD_JSR = reader["CGDD_JSR"].ToString();
model.CGDD_JSRQ = !string.IsNullOrEmpty(reader["CGDD_JSRQ"].ToString()) ? Utility.Transforms.Str2DateTime(reader["CGDD_JSRQ"].ToString()) : timeNull;
model.CGDD_KW_GUID = new Guid(reader["CGDD_KW_GUID"].ToString());
model.CGDD_LYDH = reader["CGDD_LYDH"].ToString();
model.CGDD_QS = !string.IsNullOrEmpty(reader["CGDD_QS"].ToString()) ? Utility.Transforms.Str2Int(reader["CGDD_QS"].ToString()) : intNull;
model.CGDD_RLJE = !string.IsNullOrEmpty(reader["CGDD_RLJE"].ToString()) ? Utility.Transforms.FormatDecimal(reader["CGDD_RLJE"].ToString()) : decimalNull;
model.CGDD_SD = !string.IsNullOrEmpty(reader["CGDD_SD"].ToString()) ? Utility.Transforms.Str2Int(reader["CGDD_SD"].ToString()) : intNull;
model.CGDD_SDR = reader["CGDD_SDR"].ToString();
...................
可是,当实体类中的过多时,很是浪费功夫!
各位在普通的三层架构中,都是如何更方便简单的赋值呢?
------解决方案--------------------没有办法啊!只能一个一个来...
------解决方案--------------------用ORM===》ENTITYFRAMEWORK
------解决方案--------------------1:用ORM工具 比如Linq to sql,EF,nhibernate
2:可以自己写简单的代码生成工具
3:第三方代码工具 写模板代码
------解决方案--------------------