public Update(string targetdb = null) { excutParBag = new ExcutParBag_Update(); this.SetTargetDb(targetdb.ToSafeString()); ((ExcutParBag_Update)excutParBag).excutEnum = ExcutEnum.Update; ((ExcutParBag_Update)excutParBag).SetType(typeof(T)); }
public UpdateIns(T data, string targetdb = null) { excutParBag = new ExcutParBag_Update(); this.SetTargetDb(targetdb.ToSafeString()); ((ExcutParBag_Update)excutParBag).excutEnum = ExcutEnum.Update; ((ExcutParBag_Update)excutParBag).data = data; }
//构建更新 protected override void UpdateCommandText() { base.UpdateCommandText(); ExcutParBag_Update bagPar = (ExcutParBag_Update)this.excutParBag; StringBuilder updateSQL = new StringBuilder(); //update语句 StringBuilder whereSQL = new StringBuilder(); //update条件语句 updateSQL.Append("UPDATE ").Append(bagPar.tableName).Append(" SET "); if (bagPar.condition != null) { whereSQL.AppendFormat(this.SetWhere(bagPar.condition)); } if (bagPar.data != null) { whereSQL.Append(" WHERE "); var keyValue = (from p in bagPar.PropertyFileds where p.isKey == true select p).FirstOrDefault(); var shortguid = "_" + Bitter.Tools.Utils.GuidExtends.ShortGuid(); whereSQL.AppendFormat(keyValue.filedName + "=@{0} ", keyValue.filedName + shortguid); this.Parameters.Add("@" + keyValue.filedName + shortguid, keyValue.value, keyValue); } else { if (bagPar.condition != null) { whereSQL.Append(" WHERE "); whereSQL.AppendFormat(this.SetWhere(bagPar.condition)); } } if (bagPar.updatePair != null && bagPar.updatePair.Count > 0) { foreach (UpdatePair p in bagPar.updatePair) { var pf = bagPar.PropertyFileds.Where(px => px.filedName == p.columnName).FirstOrDefault(); var shortguid = "_" + Bitter.Tools.Utils.GuidExtends.ShortGuid(); updateSQL.AppendFormat("{0}=@{1},", p.columnName, p.columnName + shortguid); this.Parameters.Add("@" + p.columnName + shortguid, p.columnValue, pf); } } else { if (bagPar.data != null) { foreach (var p in bagPar.PropertyFileds) { var shortguid = "_" + Bitter.Tools.Utils.GuidExtends.ShortGuid(); updateSQL.AppendFormat("{0}=@{1},", p.filedName, p.filedName + shortguid); this.Parameters.Add("@" + p.filedName + shortguid, p.value, p); } } } this.CommandText = string.Format("{0}{1};", updateSQL.ToString().Substring(0, updateSQL.ToString().Length - 1), whereSQL.ToString()); }
public UpdateIns() { excutParBag = new ExcutParBag_Update(); }