//构建新增 protected override void InsertCommandText(bool IsOutIdentity = false) { base.InsertCommandText(); ExcutParBag_Insert bagPar = (ExcutParBag_Insert)this.excutParBag; string fields = string.Empty; string values = string.Empty; foreach (FiledProperty filed in bagPar.PropertyFileds) { string propertyValue = string.Empty; if ((filed.isKey && !filed.isIdentity) || (!filed.isIdentity)) { var shortguid = "_" + Bitter.Tools.Utils.GuidExtends.ShortGuid(); fields += filed.filedName + ','; values += "@" + filed.filedName + shortguid + ','; var val = filed.value; this.Parameters.Add("@" + filed.filedName + shortguid, ((val == null && filed.isNull) || (filed.typeName.ToLower() == "string" && string.IsNullOrWhiteSpace(val == null ? string.Empty : val.ToString()))) ? DBNull.Value : val, Utils.SqlTypeString2SqlType(filed.typeName.ToLower())); } } var selectParimaryKey = "SELECT @@IDENTITY AS FKey;"; if (!bagPar.isIdentityModel) { var keyName = bagPar.keyName; var keyValue = (from p in bagPar.PropertyFileds where p.isKey = true select p).Select(x => x.value); selectParimaryKey = "SELECT '" + keyValue + "' AS FKey;"; } this.CommandText = string.Format("INSERT INTO {0} ({1}) VALUES ({2}){3}", bagPar.tableName, fields.Substring(0, fields.Length - 1), values.Substring(0, values.Length - 1), selectParimaryKey); }
public InsertIns(T data, bool isOutIdentity) { excutParBag = new ExcutParBag_Insert(); ((ExcutParBag_Insert)excutParBag).excutEnum = ExcutEnum.Insert; ((ExcutParBag_Insert)excutParBag).SetType(typeof(T)); ((ExcutParBag_Insert)excutParBag).data = data; ((ExcutParBag_Insert)excutParBag).isOutIdentity = true; //插入后获取 Identity CheckedIdentityVlaue(); }
public InsertIns(T data, string targetdb = null) { excutParBag = new ExcutParBag_Insert(); this.SetTargetDb(targetdb.ToSafeString()); data._targetdb = targetdb; ((ExcutParBag_Insert)excutParBag).excutEnum = ExcutEnum.Insert; ((ExcutParBag_Insert)excutParBag).data = data; ((ExcutParBag_Insert)excutParBag).isOutIdentity = false; // CheckedIdentityVlaue(); }