public virtual T ExecuteReturnEntity() { ExecuteCommandIdentityIntoEntity(); return(InsertObjs.First()); }
public async Task <T> ExecuteReturnEntityAsync() { await ExecuteCommandIdentityIntoEntityAsync(); return(InsertObjs.First()); }
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 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); }