private void GetOutputParameterValues(DbCommand cmd, out IDictionary <string, object> outValues) { try { outValues = new Dictionary <string, object>(); foreach (DbParameter p in cmd.Parameters) { //如果是输出参数直接跳过 if (p.Direction == ParameterDirection.Input) { continue; } if (p.Value == DBNull.Value) { p.Value = null; } //获取返回值 if (p.Direction == ParameterDirection.ReturnValue) { returnValue = CoreHelper.ConvertValue <int>(p.Value); } outValues.Add(p.ParameterName.Substring(1), p.Value); } } catch { throw; } }
/// <summary> /// 返回字典 /// </summary> /// <typeparam name="TResult"></typeparam> /// <param name="propertyName"></param> /// <returns></returns> public IDictionary <TResult, IList <T> > ToDictionary <TResult>(string propertyName) { IDictionary <TResult, IList <T> > group = new Dictionary <TResult, IList <T> >(); if (this.Count == 0) { return(group); } lock (group) { foreach (T t in this) { object obj = CoreHelper.GetPropertyValue(t, propertyName); TResult value = CoreHelper.ConvertValue <TResult>(obj); if (!group.ContainsKey(value)) { group[value] = new SourceList <T>(); } group[value].Add(t); } return(group); } }
/// <summary> /// 执行当前 /// </summary> /// <typeparam name="TResult"></typeparam> /// <returns></returns> public TResult ToScalar <TResult>() { object obj = this.ToScalar(); if (obj == null) { return(default(TResult)); } return(CoreHelper.ConvertValue <TResult>(obj)); }
/// <summary> /// 插入一个实体 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="fields"></param> /// <param name="values"></param> /// <returns></returns> public int Insert <T, TResult>(Table table, Field[] fields, object[] values, out TResult retVal) where T : Entity { List <FieldValue> fvlist = DataHelper.CreateFieldValue(fields, values, true); object retValue; int ret = dbBatch.Insert <T>(table, fvlist, out retValue); retVal = CoreHelper.ConvertValue <TResult>(retValue); return(ret); }
/// <summary> /// 按要求改变某列值 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="readName"></param> /// <param name="changeName"></param> /// <param name="revalue"></param> public void Revalue <T>(string readName, string changeName, ReturnValue <T> revalue) { if (!this.Columns.Contains(readName)) { throw new DataException(string.Format("当前表中不存在字段【{0}】!", readName)); } if (!this.Columns.Contains(changeName)) { throw new DataException(string.Format("当前表中不存在字段【{0}】!", changeName)); } //按要求改变值 foreach (DataRow row in this.Rows) { row[changeName] = revalue(CoreHelper.ConvertValue <T>(row[readName])); } }
/// <summary> /// 插入数据 /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="TResult"></typeparam> /// <param name="table"></param> /// <param name="fvs"></param> /// <param name="retVal"></param> /// <returns></returns> public int Insert <T, TResult>(Table table, FieldValue[] fvs, out TResult retVal) where T : Entity { List <FieldValue> list = new List <FieldValue>(fvs); list.ForEach(p => { if (p.Value is Field) { p.IsIdentity = true; } }); object retValue; int ret = dbBatch.Insert <T>(table, list, out retValue); retVal = CoreHelper.ConvertValue <TResult>(retValue); return(ret); }
/// <summary> /// 插入数据 /// </summary> /// <typeparam name="TResult"></typeparam> /// <param name="creator"></param> /// <param name="identityValue"></param> /// <returns></returns> public int Execute <TResult>(InsertCreator creator, out TResult identityValue) { identityValue = default(TResult); if (creator.Table == null) { throw new DataException("用创建器操作时,表不能为null!"); } if ((IField)creator.IdentityField == null) { throw new DataException("返回主键值时需要设置KeyField!"); } object retVal; int ret = dbProvider.Insert <ViewEntity>(creator.Table, creator.FieldValues, this, creator.IdentityField, creator.SequenceName, true, out retVal); identityValue = CoreHelper.ConvertValue <TResult>(retVal); return(ret); }
private int GetCount(QuerySection <T> query) { string countString = query.CountString; string cacheKey = GetCacheKey(countString, this.Parameters); object obj = GetCache <T>("Count", cacheKey); if (obj != null) { return(CoreHelper.ConvertValue <int>(obj)); } //添加参数到Command中 queryCommand = dbProvider.CreateSqlCommand(countString, query.Parameters); object value = dbProvider.ExecuteScalar(queryCommand, dbTran); int ret = CoreHelper.ConvertValue <int>(value); SetCache <T>("Count", cacheKey, ret); return(ret); }
/// <summary> /// 返回指定类型的数据 /// </summary> /// <typeparam name="TResult"></typeparam> /// <param name="name"></param> /// <returns></returns> public TResult GetValue <TResult>(string name) { return(CoreHelper.ConvertValue <TResult>(GetValue(name))); }
/// <summary> /// 返回指定类型的数据 /// </summary> /// <typeparam name="TResult"></typeparam> /// <param name="index"></param> /// <returns></returns> public TResult GetValue <TResult>(int index) { return(CoreHelper.ConvertValue <TResult>(GetValue(index))); }
/// <summary> /// 执行当前Proc返回一个值,并输出参数值 /// </summary> /// <typeparam name="TResult"></typeparam> /// <param name="outValues"></param> /// <returns></returns> public TResult ToScalar <TResult>(out IDictionary <string, object> outValues) { object obj = this.ToScalar(out outValues); return(CoreHelper.ConvertValue <TResult>(obj)); }
/// <summary> /// 执行当前Proc并返回一个值 /// </summary> /// <typeparam name="TResult"></typeparam> /// <returns></returns> public TResult ToScalar <TResult>() { object obj = this.ToScalar(); return(CoreHelper.ConvertValue <TResult>(obj)); }