public async Task <bool> ExecuteCommandIdentityIntoEntityAsync() { var result = InsertObjs.First(); var identityKeys = GetIdentityKeys(); if (identityKeys.Count == 0) { return(await this.ExecuteCommandAsync() > 0); } var idValue = await ExecuteReturnBigIdentityAsync(); Check.Exception(identityKeys.Count > 1, "ExecuteCommandIdentityIntoEntity does not support multiple identity keys"); var identityKey = identityKeys.First(); object setValue = 0; if (idValue > int.MaxValue) { setValue = idValue; } else { setValue = Convert.ToInt32(idValue); } this.Context.EntityMaintenance.GetProperty <T>(identityKey).SetValue(result, setValue, null); return(idValue > 0); }
private string _ExecuteCommand() { if (InsertBuilder.DbColumnInfoList.HasValue()) { var pks = GetPrimaryKeys(); foreach (var item in InsertBuilder.DbColumnInfoList) { var isPk = pks.Any(y => y.Equals(item.DbColumnName, StringComparison.CurrentCultureIgnoreCase)) || item.IsPrimarykey; if (isPk && item.PropertyType == UtilConstants.GuidType && item.Value.ObjToString() == Guid.Empty.ToString()) { item.Value = Guid.NewGuid(); if (InsertObjs.First().GetType().GetProperties().Any(it => it.Name == item.PropertyName)) { InsertObjs.First().GetType().GetProperties().First(it => it.Name == item.PropertyName).SetValue(InsertObjs.First(), item.Value, null); } } } } InsertBuilder.IsReturnIdentity = false; PreToSql(); AutoRemoveDataCache(); string sql = InsertBuilder.ToSqlString(); RestoreMapping(); Before(sql); return(sql); }
public override bool ExecuteCommandIdentityIntoEntity() { var result = InsertObjs.First(); var identityKeys = GetIdentityKeys(); if (identityKeys.Count == 0) { return(this.ExecuteCommand() > 0); } var idValue = ExecuteReturnBigIdentity(); Check.Exception(identityKeys.Count > 1, "ExecuteCommandIdentityIntoEntity does not support multiple identity keys"); var identityKey = identityKeys.First(); object setValue = 0; if (idValue > int.MaxValue) { setValue = idValue; } else { setValue = Convert.ToInt32(idValue); } var propertyName = this.Context.EntityMaintenance.GetPropertyName <T>(identityKey); typeof(T).GetProperties().First(t => t.Name.ToUpper() == propertyName.ToUpper()).SetValue(result, setValue, null); return(idValue > 0); }
internal void Init() { InsertBuilder.EntityInfo = this.EntityInfo; Check.Exception(InsertObjs == null || InsertObjs.Count() == 0, "InsertObjs is null"); int i = 0; foreach (var item in InsertObjs) { List <DbColumnInfo> insertItem = new List <DbColumnInfo>(); foreach (var column in EntityInfo.Columns) { var columnInfo = new DbColumnInfo() { Value = column.PropertyInfo.GetValue(item, null), DbColumnName = GetDbColumnName(column.PropertyName), PropertyName = column.PropertyName, PropertyType = UtilMethods.GetUnderType(column.PropertyInfo), TableId = i }; if (columnInfo.PropertyType.IsEnum()) { columnInfo.Value = Convert.ToInt64(columnInfo.Value); } insertItem.Add(columnInfo); } this.InsertBuilder.DbColumnInfoList.AddRange(insertItem); ++i; } }
protected override void PreToSql() { var identities = GetSeqNames(); var insertCount = InsertObjs.Count(); InsertBuilder.OracleSeqInfoList = new Dictionary <string, int>(); if ((identities.HasValue() && insertCount > 1) || InsertBuilder.IsBlukCopy) { Check.Exception(identities.Count != identities.Distinct().Count(), "The field sequence needs to be unique"); foreach (var seqName in identities) { int seqBeginValue = 0; seqBeginValue = this.Ado.GetInt("select " + seqName + ".Nextval from dual"); //Console.WriteLine(seqBeginValue); var nextLength = insertCount - 1; if (nextLength > 0) { StringBuilder sb = new StringBuilder(); sb.AppendLine(" select " + seqName + ".nextval,t.* from ("); for (int i = 0; i < nextLength; i++) { sb.AppendLine(" select 1 from dual"); if (i < (nextLength - 1)) { sb.AppendLine("union all"); } } sb.AppendLine(" )t"); this.Ado.SqlQuery <int>(sb.ToString()); } InsertBuilder.OracleSeqInfoList.Add(seqName, seqBeginValue); } } base.PreToSql(); }
public virtual int ExecuteCommand() { if (this.InsertObjs.Count() == 1 && this.InsertObjs.First() == null) { return(0); } if (InsertBuilder.DbColumnInfoList.HasValue()) { var pks = GetPrimaryKeys(); foreach (var item in InsertBuilder.DbColumnInfoList) { var isPk = pks.Any(y => y.Equals(item.DbColumnName, StringComparison.CurrentCultureIgnoreCase)) || item.IsPrimarykey; if (isPk && item.PropertyType == UtilConstants.GuidType && item.Value.ObjToString() == Guid.Empty.ToString()) { item.Value = Guid.NewGuid(); if (InsertObjs.First().GetType().GetProperties().Any(it => it.Name == item.PropertyName)) { InsertObjs.First().GetType().GetProperties().First(it => it.Name == item.PropertyName).SetValue(InsertObjs.First(), item.Value, null); } } } } InsertBuilder.IsReturnIdentity = false; PreToSql(); AutoRemoveDataCache(); string sql = InsertBuilder.ToSqlString(); RestoreMapping(); Before(sql); var result = Ado.ExecuteCommand(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()); After(sql, null); return(result); }
public virtual bool ExecuteCommandIdentityIntoEntity() { var result = InsertObjs.First(); var identityKeys = GetIdentityKeys(); if (identityKeys.Count == 0) { return(this.ExecuteCommand() > 0); } var idValue = ExecuteReturnBigIdentity(); Check.Exception(identityKeys.Count > 1, "ExecuteCommandIdentityIntoEntity does not support multiple identity keys"); var identityKey = identityKeys.First(); object setValue = 0; if (idValue > int.MaxValue) { setValue = idValue; } else { setValue = Convert.ToInt32(idValue); } this.Context.EntityProvider.GetProperty <T>(identityKey).SetValue(result, setValue, null); return(idValue > 0); }
public T ExecuteReturnEntity() { var result = InsertObjs.First(); var identityKeys = GetIdentityKeys(); if (identityKeys.Count == 0) { return(result); } var idValue = ExecuteReturnIdentity(); Check.Exception(identityKeys.Count > 1, "ExecuteReutrnEntity does not support multiple identity keys"); var identityKey = identityKeys.First(); this.Context.EntityProvider.GetProperty <T>(identityKey).SetValue(result, idValue, null); return(result); }
protected override void PreToSql() { var identities = GetSeqNames(); var insertCount = InsertObjs.Count(); InsertBuilder.OracleSeqInfoList = new Dictionary <string, int>(); if (identities.HasValue() && insertCount > 1) { Check.Exception(identities.Count != identities.Distinct().Count(), "The field sequence needs to be unique"); foreach (var seqName in identities) { int seqBeginValue = 0; this.Ado.ExecuteCommand("alter sequence " + seqName + " increment by " + insertCount); seqBeginValue = this.Ado.GetInt("select " + seqName + ".Nextval from dual") - insertCount; this.Ado.ExecuteCommand("alter sequence " + seqName + " increment by " + 1); InsertBuilder.OracleSeqInfoList.Add(seqName, seqBeginValue); } } base.PreToSql(); }
internal void Init() { InsertBuilder.EntityInfo = this.EntityInfo; Check.Exception(InsertObjs == null || InsertObjs.Count() == 0, "InsertObjs is null"); int i = 0; foreach (var item in InsertObjs) { List <DbColumnInfo> insertItem = new List <DbColumnInfo>(); if (item is Dictionary <string, object> ) { SetInsertItemByDic(i, item, insertItem); } else { SetInsertItemByEntity(i, item, insertItem); } this.InsertBuilder.DbColumnInfoList.AddRange(insertItem); ++i; } }
public async Task <T> ExecuteReturnEntityAsync() { await ExecuteCommandIdentityIntoEntityAsync(); return(InsertObjs.First()); }
public virtual T ExecuteReturnEntity() { ExecuteCommandIdentityIntoEntity(); return(InsertObjs.First()); }