diff --git a/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs index b18f4f8b1..24f3fd0dd 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs @@ -781,35 +781,8 @@ namespace SqlSugar } public virtual List SqlQuery(string sql, params SugarParameter[] parameters) { - this.Context.InitMappingInfo(); - var builder = InstanceFactory.GetSqlbuilder(this.Context.CurrentConnectionConfig); - builder.SqlQueryBuilder.sql.Append(sql); - if (parameters != null && parameters.Any()) - builder.SqlQueryBuilder.Parameters.AddRange(parameters); - var dataReader = this.GetDataReader(builder.SqlQueryBuilder.ToSqlString(), builder.SqlQueryBuilder.Parameters.ToArray()); - List result = null; - if (typeof(T) == UtilConstants.ObjType) - { - result = this.Context.Utilities.DataReaderToExpandoObjectList(dataReader).Select(it => ((T)(object)it)).ToList(); - } - else - { - result = this.DbBind.DataReaderToList(typeof(T), dataReader); - } - builder.SqlQueryBuilder.Clear(); - if (this.Context.Ado.DataReaderParameters != null) - { - foreach (IDataParameter item in this.Context.Ado.DataReaderParameters) - { - var parameter = parameters.FirstOrDefault(it => item.ParameterName.Substring(1) == it.ParameterName.Substring(1)); - if (parameter != null) - { - parameter.Value = item.Value; - } - } - this.Context.Ado.DataReaderParameters = null; - } - return result; + var result = SqlQuery(sql, parameters); + return result.Item1; } public virtual List SqlQuery(string sql, List parameters) { @@ -822,57 +795,6 @@ namespace SqlSugar return SqlQuery(sql); } } - - public virtual Task> SqlQueryAsync(string sql, object parameters = null) - { - var sugarParameters = this.GetParameters(parameters); - return SqlQueryAsync(sql, sugarParameters); - } - public virtual async Task> SqlQueryAsync(string sql, params SugarParameter[] parameters) - { - this.Context.InitMappingInfo(); - var builder = InstanceFactory.GetSqlbuilder(this.Context.CurrentConnectionConfig); - builder.SqlQueryBuilder.sql.Append(sql); - if (parameters != null && parameters.Any()) - builder.SqlQueryBuilder.Parameters.AddRange(parameters); - var dataReader = await this.GetDataReaderAsync(builder.SqlQueryBuilder.ToSqlString(), builder.SqlQueryBuilder.Parameters.ToArray()); - List result = null; - if (typeof(T) == UtilConstants.ObjType) - { - var list = await this.Context.Utilities.DataReaderToExpandoObjectListAsync(dataReader); - result = list.Select(it => ((T)(object)it)).ToList(); - } - else - { - result = await this.DbBind.DataReaderToListAsync(typeof(T), dataReader); - } - builder.SqlQueryBuilder.Clear(); - if (this.Context.Ado.DataReaderParameters != null) - { - foreach (IDataParameter item in this.Context.Ado.DataReaderParameters) - { - var parameter = parameters.FirstOrDefault(it => item.ParameterName.Substring(1) == it.ParameterName.Substring(1)); - if (parameter != null) - { - parameter.Value = item.Value; - } - } - this.Context.Ado.DataReaderParameters = null; - } - return result; - } - public virtual Task> SqlQueryAsync(string sql, List parameters) - { - if (parameters != null) - { - return SqlQueryAsync(sql, parameters.ToArray()); - } - else - { - return SqlQueryAsync(sql); - } - } - public Tuple, List> SqlQuery(string sql, object parameters = null) { var result = SqlQuery(sql, parameters); @@ -967,170 +889,51 @@ namespace SqlSugar } } - public async Task, List>> SqlQueryAsync(string sql, object parameters = null) + public virtual Task> SqlQueryAsync(string sql, object parameters = null) { - var parsmeterArray = this.GetParameters(parameters); - this.Context.InitMappingInfo(); - var builder = InstanceFactory.GetSqlbuilder(this.Context.CurrentConnectionConfig); - builder.SqlQueryBuilder.sql.Append(sql); - if (parsmeterArray != null && parsmeterArray.Any()) - builder.SqlQueryBuilder.Parameters.AddRange(parsmeterArray); - using (var dataReader = await this.GetDataReaderNoCloseAsync(builder.SqlQueryBuilder.ToSqlString(), builder.SqlQueryBuilder.Parameters.ToArray())) + var sugarParameters = this.GetParameters(parameters); + return SqlQueryAsync(sql, sugarParameters); + } + public virtual async Task> SqlQueryAsync(string sql, params SugarParameter[] parameters) + { + var result = await SqlQueryAsync(sql, parameters); + return result.Item1; + } + public virtual Task> SqlQueryAsync(string sql, List parameters) + { + if (parameters != null) { - List result = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T), dataReader); - NextResult(dataReader); - List result2 = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T2), dataReader); - builder.SqlQueryBuilder.Clear(); - if (this.Context.Ado.DataReaderParameters != null) - { - foreach (IDataParameter item in this.Context.Ado.DataReaderParameters) - { - var parameter = parsmeterArray.FirstOrDefault(it => item.ParameterName.Substring(1) == it.ParameterName.Substring(1)); - if (parameter != null) - { - parameter.Value = item.Value; - } - } - this.Context.Ado.DataReaderParameters = null; - } - return Tuple.Create, List>(result, result2); + return SqlQueryAsync(sql, parameters.ToArray()); } + else + { + return SqlQueryAsync(sql); + } + } + public async Task, List>> SqlQueryAsync(string sql, object parameters = null) + { + var result = await SqlQueryAsync(sql, parameters); + return new Tuple, List>(result.Item1, result.Item2); } public async Task, List, List>> SqlQueryAsync(string sql, object parameters = null) { - var parsmeterArray = this.GetParameters(parameters); - this.Context.InitMappingInfo(); - var builder = InstanceFactory.GetSqlbuilder(this.Context.CurrentConnectionConfig); - builder.SqlQueryBuilder.sql.Append(sql); - if (parsmeterArray != null && parsmeterArray.Any()) - builder.SqlQueryBuilder.Parameters.AddRange(parsmeterArray); - using (var dataReader = await this.GetDataReaderNoCloseAsync(builder.SqlQueryBuilder.ToSqlString(), builder.SqlQueryBuilder.Parameters.ToArray())) - { - List result = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T), dataReader); - NextResult(dataReader); - List result2 = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T2), dataReader); - NextResult(dataReader); - List result3 = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T3), dataReader); - builder.SqlQueryBuilder.Clear(); - if (this.Context.Ado.DataReaderParameters != null) - { - foreach (IDataParameter item in this.Context.Ado.DataReaderParameters) - { - var parameter = parsmeterArray.FirstOrDefault(it => item.ParameterName.Substring(1) == it.ParameterName.Substring(1)); - if (parameter != null) - { - parameter.Value = item.Value; - } - } - this.Context.Ado.DataReaderParameters = null; - } - return Tuple.Create, List, List>(result, result2, result3); - } + var result = await SqlQueryAsync(sql, parameters); + return new Tuple, List, List>(result.Item1, result.Item2, result.Item3); } public async Task, List, List, List>> SqlQueryAsync(string sql, object parameters = null) { - var parsmeterArray = this.GetParameters(parameters); - this.Context.InitMappingInfo(); - var builder = InstanceFactory.GetSqlbuilder(this.Context.CurrentConnectionConfig); - builder.SqlQueryBuilder.sql.Append(sql); - if (parsmeterArray != null && parsmeterArray.Any()) - builder.SqlQueryBuilder.Parameters.AddRange(parsmeterArray); - using (var dataReader = await this.GetDataReaderNoCloseAsync(builder.SqlQueryBuilder.ToSqlString(), builder.SqlQueryBuilder.Parameters.ToArray())) - { - List result = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T), dataReader); - NextResult(dataReader); - List result2 = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T2), dataReader); - NextResult(dataReader); - List result3 = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T3), dataReader); - NextResult(dataReader); - List result4 = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T4), dataReader); - builder.SqlQueryBuilder.Clear(); - if (this.Context.Ado.DataReaderParameters != null) - { - foreach (IDataParameter item in this.Context.Ado.DataReaderParameters) - { - var parameter = parsmeterArray.FirstOrDefault(it => item.ParameterName.Substring(1) == it.ParameterName.Substring(1)); - if (parameter != null) - { - parameter.Value = item.Value; - } - } - this.Context.Ado.DataReaderParameters = null; - } - return Tuple.Create, List, List, List>(result, result2, result3, result4); - } + var result = await SqlQueryAsync(sql, parameters); + return new Tuple, List, List, List>(result.Item1, result.Item2, result.Item3, result.Item4); } public async Task, List, List, List, List>> SqlQueryAsync(string sql, object parameters = null) { - var parsmeterArray = this.GetParameters(parameters); - this.Context.InitMappingInfo(); - var builder = InstanceFactory.GetSqlbuilder(this.Context.CurrentConnectionConfig); - builder.SqlQueryBuilder.sql.Append(sql); - if (parsmeterArray != null && parsmeterArray.Any()) - builder.SqlQueryBuilder.Parameters.AddRange(parsmeterArray); - using (var dataReader = await this.GetDataReaderNoCloseAsync(builder.SqlQueryBuilder.ToSqlString(), builder.SqlQueryBuilder.Parameters.ToArray())) - { - List result = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T), dataReader); - NextResult(dataReader); - List result2 = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T2), dataReader); - NextResult(dataReader); - List result3 = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T3), dataReader); - NextResult(dataReader); - List result4 = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T4), dataReader); - NextResult(dataReader); - List result5 = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T5), dataReader); - builder.SqlQueryBuilder.Clear(); - if (this.Context.Ado.DataReaderParameters != null) - { - foreach (IDataParameter item in this.Context.Ado.DataReaderParameters) - { - var parameter = parsmeterArray.FirstOrDefault(it => item.ParameterName.Substring(1) == it.ParameterName.Substring(1)); - if (parameter != null) - { - parameter.Value = item.Value; - } - } - this.Context.Ado.DataReaderParameters = null; - } - return Tuple.Create, List, List, List, List>(result, result2, result3, result4, result5); - } + var result = await SqlQueryAsync(sql, parameters); + return new Tuple, List, List, List, List>(result.Item1, result.Item2, result.Item3, result.Item4, result.Item5); } public async Task, List, List, List, List, List>> SqlQueryAsync(string sql, object parameters = null) { - var parsmeterArray = this.GetParameters(parameters); - this.Context.InitMappingInfo(); - var builder = InstanceFactory.GetSqlbuilder(this.Context.CurrentConnectionConfig); - builder.SqlQueryBuilder.sql.Append(sql); - if (parsmeterArray != null && parsmeterArray.Any()) - builder.SqlQueryBuilder.Parameters.AddRange(parsmeterArray); - using (var dataReader = await this.GetDataReaderNoCloseAsync(builder.SqlQueryBuilder.ToSqlString(), builder.SqlQueryBuilder.Parameters.ToArray())) - { - List result = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T), dataReader); - NextResult(dataReader); - List result2 = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T2), dataReader); - NextResult(dataReader); - List result3 = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T3), dataReader); - NextResult(dataReader); - List result4 = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T4), dataReader); - NextResult(dataReader); - List result5 = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T5), dataReader); - NextResult(dataReader); - List result6 = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T6), dataReader); - builder.SqlQueryBuilder.Clear(); - if (this.Context.Ado.DataReaderParameters != null) - { - foreach (IDataParameter item in this.Context.Ado.DataReaderParameters) - { - var parameter = parsmeterArray.FirstOrDefault(it => item.ParameterName.Substring(1) == it.ParameterName.Substring(1)); - if (parameter != null) - { - parameter.Value = item.Value; - } - } - this.Context.Ado.DataReaderParameters = null; - } - return Tuple.Create, List, List, List, List, List>(result, result2, result3, result4, result5, result6); - } + var result =await SqlQueryAsync(sql, parameters); + return new Tuple, List, List, List, List, List>(result.Item1, result.Item2, result.Item3, result.Item4, result.Item5, result.Item6); } public async Task, List, List, List, List, List, List>> SqlQueryAsync(string sql, object parameters = null) { @@ -1142,19 +945,48 @@ namespace SqlSugar builder.SqlQueryBuilder.Parameters.AddRange(parsmeterArray); using (var dataReader = await this.GetDataReaderNoCloseAsync(builder.SqlQueryBuilder.ToSqlString(), builder.SqlQueryBuilder.Parameters.ToArray())) { - List result = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T), dataReader); - NextResult(dataReader); - List result2 = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T2), dataReader); - NextResult(dataReader); - List result3 = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T3), dataReader); - NextResult(dataReader); - List result4 = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T4), dataReader); - NextResult(dataReader); - List result5 = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T5), dataReader); - NextResult(dataReader); - List result6 = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T6), dataReader); - NextResult(dataReader); - List result7 = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T7), dataReader); + DbDataReader DbReader = (DbDataReader)dataReader; + List result = null; + if (DbReader.HasRows) + { + result =await this.DbBind.DataReaderToListNoUsingAsync(typeof(T), dataReader); + } + List result2 = null; + if (DbReader.HasRows) + { + NextResult(dataReader); + result2 = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T2), dataReader); + } + List result3 = null; + if (DbReader.HasRows) + { + NextResult(dataReader); + result3 = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T3), dataReader); + } + List result4 = null; + if (DbReader.HasRows) + { + NextResult(dataReader); + result4 = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T4), dataReader); + } + List result5 = null; + if (DbReader.HasRows) + { + NextResult(dataReader); + result5 = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T5), dataReader); + } + List result6 = null; + if (DbReader.HasRows) + { + NextResult(dataReader); + result6 = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T6), dataReader); + } + List result7 = null; + if (DbReader.HasRows) + { + NextResult(dataReader); + result7 = await this.DbBind.DataReaderToListNoUsingAsync(typeof(T7), dataReader); + } builder.SqlQueryBuilder.Clear(); if (this.Context.Ado.DataReaderParameters != null) {