Browse Source

-

pull/12/MERGE
sunkaixuan 6 years ago
parent
commit
054ce37019
  1. 81
      Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs
  2. 5
      Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs
  3. 15
      Src/Asp.Net/SqlSugar/Interface/IAdo.cs

81
Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs

@ -725,6 +725,55 @@ namespace SqlSugar
return SqlQuery<T>(sql); return SqlQuery<T>(sql);
} }
} }
public virtual Task<List<T>> SqlQueryAsync<T>(string sql, object parameters = null)
{
var sugarParameters = this.GetParameters(parameters);
return SqlQueryAsync<T>(sql, sugarParameters);
}
public virtual async Task<List<T>> SqlQueryAsync<T>(string sql, params SugarParameter[] parameters)
{
this.Context.InitMappingInfo<T>();
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<T> 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<T>(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<List<T>> SqlQueryAsync<T>(string sql, List<SugarParameter> parameters)
{
if (parameters != null)
{
return SqlQueryAsync<T>(sql, parameters.ToArray());
}
else
{
return SqlQueryAsync<T>(sql);
}
}
public Tuple<List<T>, List<T2>> SqlQuery<T, T2>(string sql, object parameters = null) public Tuple<List<T>, List<T2>> SqlQuery<T, T2>(string sql, object parameters = null)
{ {
var parsmeterArray = this.GetParameters(parameters); var parsmeterArray = this.GetParameters(parameters);
@ -1041,11 +1090,26 @@ namespace SqlSugar
return GetScalar(sql, parameters.ToArray()); return GetScalar(sql, parameters.ToArray());
} }
} }
public virtual Task<object> GetScalarAsync(string sql, object parameters)
{
return GetScalarAsync(sql, this.GetParameters(parameters));
}
public virtual Task<object> GetScalarAsync(string sql, List<SugarParameter> parameters)
{
if (parameters == null)
{
return GetScalarAsync(sql);
}
else
{
return GetScalarAsync(sql, parameters.ToArray());
}
}
public virtual int ExecuteCommand(string sql, object parameters) public virtual int ExecuteCommand(string sql, object parameters)
{ {
return ExecuteCommand(sql, GetParameters(parameters)); return ExecuteCommand(sql, GetParameters(parameters));
} }
public virtual int ExecuteCommand(string sql, List<SugarParameter> parameters) public virtual int ExecuteCommandAsync(string sql, List<SugarParameter> parameters)
{ {
if (parameters == null) if (parameters == null)
{ {
@ -1056,6 +1120,21 @@ namespace SqlSugar
return ExecuteCommand(sql, parameters.ToArray()); return ExecuteCommand(sql, parameters.ToArray());
} }
} }
public virtual Task<int> ExecuteCommandAsync(string sql, object parameters)
{
return ExecuteCommandAsync(sql, GetParameters(parameters));
}
public virtual Task<int> ExecuteCommand(string sql, List<SugarParameter> parameters)
{
if (parameters == null)
{
return ExecuteCommandAsync(sql);
}
else
{
return ExecuteCommandAsync(sql, parameters.ToArray());
}
}
#endregion #endregion
#region Helper #region Helper

5
Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs

@ -794,10 +794,9 @@ namespace SqlSugar
return SaveQueuesProvider(isTran, (sql, parameters) => { return this.Ado.ExecuteCommand(sql, parameters); }); return SaveQueuesProvider(isTran, (sql, parameters) => { return this.Ado.ExecuteCommand(sql, parameters); });
} }
public Task<int> SaveQueuesAsync(bool isTran = true) public async Task<int> SaveQueuesAsync(bool isTran = true)
{ {
var result =Task.FromResult(SaveQueues(isTran)); return await SaveQueuesProvider(isTran, async(sql, parameters) => { return await this.Ado.ExecuteCommandAsync(sql, parameters); });
return result;
} }
public List<T> SaveQueues<T>(bool isTran = true) public List<T> SaveQueues<T>(bool isTran = true)
{ {

15
Src/Asp.Net/SqlSugar/Interface/IAdo.cs

@ -33,10 +33,8 @@ namespace SqlSugar
void SetCommandToAdapter(IDataAdapter adapter, DbCommand command); void SetCommandToAdapter(IDataAdapter adapter, DbCommand command);
IDataAdapter GetAdapter(); IDataAdapter GetAdapter();
DbCommand GetCommand(string sql, SugarParameter[] parameters); DbCommand GetCommand(string sql, SugarParameter[] parameters);
Task<int> ExecuteCommandAsync(string sql, params SugarParameter[] parameters);
Task<IDataReader> GetDataReaderAsync(string sql, params SugarParameter[] parameters); Task<IDataReader> GetDataReaderAsync(string sql, params SugarParameter[] parameters);
Task<IDataReader> GetDataReaderNoCloseAsync(string sql, params SugarParameter[] parameters); Task<IDataReader> GetDataReaderNoCloseAsync(string sql, params SugarParameter[] parameters);
Task<object> GetScalarAsync(string sql, params SugarParameter[] parameters);
DataTable GetDataTable(string sql, object parameters); DataTable GetDataTable(string sql, object parameters);
DataTable GetDataTable(string sql, params SugarParameter[] parameters); DataTable GetDataTable(string sql, params SugarParameter[] parameters);
DataTable GetDataTable(string sql, List<SugarParameter> parameters); DataTable GetDataTable(string sql, List<SugarParameter> parameters);
@ -49,9 +47,15 @@ namespace SqlSugar
object GetScalar(string sql, object parameters); object GetScalar(string sql, object parameters);
object GetScalar(string sql, params SugarParameter[] parameters); object GetScalar(string sql, params SugarParameter[] parameters);
object GetScalar(string sql, List<SugarParameter> parameters); object GetScalar(string sql, List<SugarParameter> parameters);
Task<object> GetScalarAsync(string sql, object parameters);
Task<object> GetScalarAsync(string sql, params SugarParameter[] parameters);
Task<object> GetScalarAsync(string sql, List<SugarParameter> parameters);
int ExecuteCommand(string sql, object parameters); int ExecuteCommand(string sql, object parameters);
int ExecuteCommand(string sql, params SugarParameter[] parameters); int ExecuteCommand(string sql, params SugarParameter[] parameters);
int ExecuteCommand(string sql, List<SugarParameter> parameters); int ExecuteCommand(string sql, List<SugarParameter> parameters);
Task<int> ExecuteCommandAsync(string sql, params SugarParameter[] parameters);
Task<int> ExecuteCommandAsync(string sql, object parameters);
Task<int> ExecuteCommandAsync(string sql, List<SugarParameter> parameters);
string GetString(string sql, object parameters); string GetString(string sql, object parameters);
string GetString(string sql, params SugarParameter[] parameters); string GetString(string sql, params SugarParameter[] parameters);
string GetString(string sql, List<SugarParameter> parameters); string GetString(string sql, List<SugarParameter> parameters);
@ -69,16 +73,19 @@ namespace SqlSugar
DateTime GetDateTime(string sql, object parameters); DateTime GetDateTime(string sql, object parameters);
DateTime GetDateTime(string sql, params SugarParameter[] parameters); DateTime GetDateTime(string sql, params SugarParameter[] parameters);
DateTime GetDateTime(string sql, List<SugarParameter> parameters); DateTime GetDateTime(string sql, List<SugarParameter> parameters);
List<T> SqlQuery<T>(string sql, object parameters = null);
Tuple<List<T>, List<T2>> SqlQuery<T,T2>(string sql, object parameters = null); Tuple<List<T>, List<T2>> SqlQuery<T,T2>(string sql, object parameters = null);
Tuple<List<T>, List<T2>, List<T3>> SqlQuery<T, T2,T3>(string sql, object parameters = null); Tuple<List<T>, List<T2>, List<T3>> SqlQuery<T, T2,T3>(string sql, object parameters = null);
Tuple<List<T>, List<T2>, List<T3>,List<T4>> SqlQuery<T,T2,T3,T4>(string sql, object parameters = null); Tuple<List<T>, List<T2>, List<T3>,List<T4>> SqlQuery<T,T2,T3,T4>(string sql, object parameters = null);
Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>> SqlQuery<T, T2, T3, T4,T5>(string sql, object parameters = null); Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>> SqlQuery<T, T2, T3, T4,T5>(string sql, object parameters = null);
Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>> SqlQuery<T, T2, T3, T4, T5,T6>(string sql, object parameters = null); Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>> SqlQuery<T, T2, T3, T4, T5,T6>(string sql, object parameters = null);
Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>, List<T7>> SqlQuery<T, T2, T3, T4, T5, T6,T7>(string sql, object parameters = null); Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>, List<T7>> SqlQuery<T, T2, T3, T4, T5, T6,T7>(string sql, object parameters = null);
List<T> SqlQuery<T>(string sql, object parameters = null);
List<T> SqlQuery<T>(string sql, params SugarParameter[] parameters); List<T> SqlQuery<T>(string sql, params SugarParameter[] parameters);
List<T> SqlQuery<T>(string sql, List<SugarParameter> parameters); List<T> SqlQuery<T>(string sql, List<SugarParameter> parameters);
Task<List<T>> SqlQueryAsync<T>(string sql, object parameters = null);
Task<List<T>> SqlQueryAsync<T>(string sql, List<SugarParameter> parameters);
Task<List<T>> SqlQueryAsync<T>(string sql, params SugarParameter[] parameters);
T SqlQuerySingle<T>(string sql, object whereObj = null); T SqlQuerySingle<T>(string sql, object whereObj = null);
T SqlQuerySingle<T>(string sql, params SugarParameter[] parameters); T SqlQuerySingle<T>(string sql, params SugarParameter[] parameters);
T SqlQuerySingle<T>(string sql, List<SugarParameter> parameters); T SqlQuerySingle<T>(string sql, List<SugarParameter> parameters);

Loading…
Cancel
Save