public void GetDbParaByDataRow(DataRow row, DbList <DbParameter> dbParas, EList <CKeyValue> sqlParaNameList, EList <CKeyValue> tableColumns) { dbParas.Clear(); if (null == row) { return; } CKeyValue kv = null; Type type = null; object vObj = null; string paraTypeStr = ""; foreach (var item in sqlParaNameList) { kv = tableColumns[item.Key]; if (null == kv) { continue; } if (string.IsNullOrEmpty(paraTypeStr)) { paraTypeStr = item.other.ToString(); } vObj = row[kv.Value.ToString()]; type = kv.other as Type; type = null == type ? typeof(string) : type; GetDbParaByBaseType(type, paraTypeStr, vObj, item.Value.ToString(), dbParas); } }
/// <summary> /// 根据数据实体(接口方法参数中包含)和带参数的sql语句中包含的参数集合来创建DbParameter集合 /// </summary> /// <param name="entity">数据实体(接口方法参数)</param> /// <param name="dbParas">DbParameter集合</param> /// <param name="paraNameList">带参数的sql包含的参数集合</param> public void GetDbParaListByEntity(object entity, DbList <DbParameter> dbParas, EList <CKeyValue> sqlParaNameList) { dbParas.Clear(); if (null == entity) { return; } CKeyValue kv = null; object vObj = null; string paraTypeStr = ""; PropertyInfo[] piArr = entity.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); foreach (PropertyInfo item in piArr) { kv = sqlParaNameList[item.Name.ToLower()]; if (null == kv) { continue; } if (string.IsNullOrEmpty(paraTypeStr)) { paraTypeStr = kv.other.ToString(); } //throw new Exception("未引入与[" + paraTypeStr + "]类型相关的程序集"); vObj = item.GetValue(entity, null); GetDbParaByBaseType(item.PropertyType, paraTypeStr, vObj, kv.Value.ToString(), dbParas); } }