public Delete(string targetdb = null) { excutParBag = new ExcutParBag_Delete(); this.SetTargetDb(targetdb.ToSafeString()); excutParBag.excutEnum = ExcutEnum.Delete; excutParBag.SetType(typeof(T)); }
public DeleteIns(T data, string targetdb = null) { excutParBag = new ExcutParBag_Delete(); this.SetTargetDb(targetdb.ToSafeString()); excutParBag.excutEnum = ExcutEnum.Delete; this.excutParBag.data = data; }
//构建删除 protected override void DeleteCommandText() { base.DeleteCommandText(); ExcutParBag_Delete bagPar = (ExcutParBag_Delete)this.excutParBag; StringBuilder deleteSQL = new StringBuilder(); //delete语句 deleteSQL.Append("DELETE FROM ").Append(bagPar.tableName); StringBuilder whereSQL = new StringBuilder(); //delete条件 if (bagPar.condition != null) { whereSQL.Append(" WHERE "); whereSQL.AppendFormat(this.SetWhere(bagPar.condition)); } else if (bagPar.data != null) { whereSQL.Append(" WHERE "); var keyName = bagPar.keyName; var keyFiled = (from p in bagPar.PropertyFileds where p.isKey = true select p).FirstOrDefault(); var shortguid = "_" + Bitter.Tools.Utils.GuidExtends.ShortGuid(); this.Parameters.Add("@" + bagPar.keyName + shortguid, ((keyFiled == null && keyFiled.isNull) || (keyFiled.typeName.ToLower() == "string" && string.IsNullOrWhiteSpace(keyFiled.value == null ? string.Empty : keyFiled.value.ToString()))) ? DBNull.Value : keyFiled.value, Utils.SqlTypeString2SqlType(keyFiled.typeName.ToLower())); whereSQL.AppendFormat("{0}=@{1}", keyFiled.filedName, keyFiled.filedName + shortguid); } this.CommandText = string.Format("{0}{1};", deleteSQL.ToString(), whereSQL.ToString()); }
public DeleteIns() { excutParBag = new ExcutParBag_Delete(); excutParBag.excutEnum = ExcutEnum.Delete; }