Browse Source

-

pull/12/MERGE
sunkaixuan 6 years ago
parent
commit
d1c6c2816b
  1. 242
      Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs
  2. 65
      Src/Asp.Net/SqlSugar/Interface/IAdo.cs

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

@ -442,10 +442,8 @@ namespace SqlSugar
SetConnectionEnd(sql);
}
}
#endregion
#region Core Async
public virtual async Task<int> ExecuteCommandAsync(string sql, params SugarParameter[] parameters)
public virtual async Task<int> ExecuteCommandAsync(string sql, params SugarParameter[] parameters)
{
try
{
@ -457,7 +455,7 @@ namespace SqlSugar
ExecuteProcessingSQL(ref sql, parameters);
ExecuteBefore(sql, parameters);
var sqlCommand = GetCommand(sql, parameters);
int count =await sqlCommand.ExecuteNonQueryAsync();
int count = await sqlCommand.ExecuteNonQueryAsync();
if (this.IsClearParameters)
sqlCommand.Parameters.Clear();
ExecuteAfter(sql, parameters);
@ -489,7 +487,7 @@ namespace SqlSugar
ExecuteProcessingSQL(ref sql, parameters);
ExecuteBefore(sql, parameters);
var sqlCommand = GetCommand(sql, parameters);
var sqlDataReader =await sqlCommand.ExecuteReaderAsync(this.IsAutoClose() ? CommandBehavior.CloseConnection : CommandBehavior.Default);
var sqlDataReader = await sqlCommand.ExecuteReaderAsync(this.IsAutoClose() ? CommandBehavior.CloseConnection : CommandBehavior.Default);
if (isSp)
DataReaderParameters = sqlCommand.Parameters;
if (this.IsClearParameters)
@ -548,7 +546,7 @@ namespace SqlSugar
ExecuteProcessingSQL(ref sql, parameters);
ExecuteBefore(sql, parameters);
var sqlCommand = GetCommand(sql, parameters);
var scalar =await sqlCommand.ExecuteScalarAsync();
var scalar = await sqlCommand.ExecuteScalarAsync();
//scalar = (scalar == null ? 0 : scalar);
if (this.IsClearParameters)
sqlCommand.Parameters.Clear();
@ -568,6 +566,11 @@ namespace SqlSugar
SetConnectionEnd(sql);
}
}
public virtual Task<DataSet> GetDataSetAllAsync(string sql, params SugarParameter[] parameters)
{
//False asynchrony . No Support DataSet
return Task.FromResult(GetDataSetAll(sql,parameters));
}
#endregion
#region Methods
@ -591,22 +594,43 @@ namespace SqlSugar
return GetString(sql, parameters.ToArray());
}
}
public virtual int GetInt(string sql, object parameters)
public virtual Task<string> GetStringAsync(string sql, object parameters)
{
return GetInt(sql, this.GetParameters(parameters));
return GetStringAsync(sql, this.GetParameters(parameters));
}
public virtual async Task<string> GetStringAsync(string sql, params SugarParameter[] parameters)
{
return Convert.ToString(await GetScalarAsync(sql, parameters));
}
public virtual Task<string> GetStringAsync(string sql, List<SugarParameter> parameters)
{
if (parameters == null)
{
return GetStringAsync(sql);
}
else
{
return GetStringAsync(sql, parameters.ToArray());
}
}
public virtual long GetLong(string sql, object parameters)
{
return Convert.ToInt64(GetScalar(sql, GetParameters(parameters)));
}
public virtual int GetInt(string sql, params SugarParameter[] parameters)
public virtual async Task<long> GetLongAsync(string sql, object parameters)
{
return GetScalar(sql, parameters).ObjToInt();
return Convert.ToInt64(await GetScalarAsync(sql, GetParameters(parameters)));
}
public virtual async Task<int> GetIntAsync(string sql, params SugarParameter[] parameters)
public virtual int GetInt(string sql, object parameters)
{
var list = await GetScalarAsync(sql, parameters);
return list.ObjToInt();
return GetInt(sql, this.GetParameters(parameters));
}
public virtual int GetInt(string sql, List<SugarParameter> parameters)
{
@ -619,6 +643,32 @@ namespace SqlSugar
return GetInt(sql, parameters.ToArray());
}
}
public virtual int GetInt(string sql, params SugarParameter[] parameters)
{
return GetScalar(sql, parameters).ObjToInt();
}
public virtual Task<int> GetIntAsync(string sql, object parameters)
{
return GetIntAsync(sql, this.GetParameters(parameters));
}
public virtual Task<int> GetIntAsync(string sql, List<SugarParameter> parameters)
{
if (parameters == null)
{
return GetIntAsync(sql);
}
else
{
return GetIntAsync(sql, parameters.ToArray());
}
}
public virtual async Task<int> GetIntAsync(string sql, params SugarParameter[] parameters)
{
var list = await GetScalarAsync(sql, parameters);
return list.ObjToInt();
}
public virtual Double GetDouble(string sql, object parameters)
{
return GetDouble(sql, this.GetParameters(parameters));
@ -638,6 +688,29 @@ namespace SqlSugar
return GetDouble(sql, parameters.ToArray());
}
}
public virtual Task<Double> GetDoubleAsync(string sql, object parameters)
{
return GetDoubleAsync(sql, this.GetParameters(parameters));
}
public virtual async Task<Double> GetDoubleAsync(string sql, params SugarParameter[] parameters)
{
var result = await GetScalarAsync(sql, parameters);
return result.ObjToMoney();
}
public virtual Task<Double> GetDoubleAsync(string sql, List<SugarParameter> parameters)
{
if (parameters == null)
{
return GetDoubleAsync(sql);
}
else
{
return GetDoubleAsync(sql, parameters.ToArray());
}
}
public virtual decimal GetDecimal(string sql, object parameters)
{
return GetDecimal(sql, this.GetParameters(parameters));
@ -657,6 +730,31 @@ namespace SqlSugar
return GetDecimal(sql, parameters.ToArray());
}
}
public virtual Task<decimal> GetDecimalAsync(string sql, object parameters)
{
return GetDecimalAsync(sql, this.GetParameters(parameters));
}
public virtual async Task<decimal> GetDecimalAsync(string sql, params SugarParameter[] parameters)
{
var result =await GetScalarAsync(sql, parameters);
return result.ObjToDecimal();
}
public virtual Task<decimal> GetDecimalAsync(string sql, List<SugarParameter> parameters)
{
if (parameters == null)
{
return GetDecimalAsync(sql);
}
else
{
return GetDecimalAsync(sql, parameters.ToArray());
}
}
public virtual DateTime GetDateTime(string sql, object parameters)
{
return GetDateTime(sql, this.GetParameters(parameters));
@ -676,6 +774,32 @@ namespace SqlSugar
return GetDateTime(sql, parameters.ToArray());
}
}
public virtual Task<DateTime> GetDateTimeAsync(string sql, object parameters)
{
return GetDateTimeAsync(sql, this.GetParameters(parameters));
}
public virtual async Task<DateTime> GetDateTimeAsync(string sql, params SugarParameter[] parameters)
{
var list = await GetScalarAsync(sql, parameters);
return list.ObjToDate();
}
public virtual Task<DateTime> GetDateTimeAsync(string sql, List<SugarParameter> parameters)
{
if (parameters == null)
{
return GetDateTimeAsync(sql);
}
else
{
return GetDateTimeAsync(sql, parameters.ToArray());
}
}
public virtual List<T> SqlQuery<T>(string sql, object parameters = null)
{
var sugarParameters = this.GetParameters(parameters);
@ -713,7 +837,6 @@ namespace SqlSugar
}
return result;
}
public virtual List<T> SqlQuery<T>(string sql, List<SugarParameter> parameters)
{
if (parameters != null)
@ -725,6 +848,7 @@ namespace SqlSugar
return SqlQuery<T>(sql);
}
}
public virtual Task<List<T>> SqlQueryAsync<T>(string sql, object parameters = null)
{
var sugarParameters = this.GetParameters(parameters);
@ -774,6 +898,7 @@ namespace SqlSugar
return SqlQueryAsync<T>(sql);
}
}
public Tuple<List<T>, List<T2>> SqlQuery<T, T2>(string sql, object parameters = null)
{
var parsmeterArray = this.GetParameters(parameters);
@ -1199,21 +1324,26 @@ namespace SqlSugar
var result = SqlQuery<T>(sql, parameters);
return result == null ? default(T) : result.FirstOrDefault();
}
public virtual dynamic SqlQueryDynamic(string sql, object parameters = null)
public virtual async Task<T> SqlQuerySingleAsync<T>(string sql, object parameters = null)
{
var dt = this.GetDataTable(sql, parameters);
return dt == null ? null : this.Context.Utilities.DataTableToDynamic(dt);
var result =await SqlQueryAsync<T>(sql, parameters);
return result == null ? default(T) : result.FirstOrDefault();
}
public virtual dynamic SqlQueryDynamic(string sql, params SugarParameter[] parameters)
public virtual async Task<T> SqlQuerySingleAsync<T>(string sql, params SugarParameter[] parameters)
{
var dt = this.GetDataTable(sql, parameters);
return dt == null ? null : this.Context.Utilities.DataTableToDynamic(dt);
var result =await SqlQueryAsync<T>(sql, parameters);
return result == null ? default(T) : result.FirstOrDefault();
}
public dynamic SqlQueryDynamic(string sql, List<SugarParameter> parameters)
public virtual async Task<T> SqlQuerySingleAsync<T>(string sql, List<SugarParameter> parameters)
{
var dt = this.GetDataTable(sql, parameters);
return dt == null ? null : this.Context.Utilities.DataTableToDynamic(dt);
var result =await SqlQueryAsync<T>(sql, parameters);
return result == null ? default(T) : result.FirstOrDefault();
}
public virtual DataTable GetDataTable(string sql, params SugarParameter[] parameters)
{
var ds = GetDataSetAll(sql, parameters);
@ -1235,6 +1365,31 @@ namespace SqlSugar
return GetDataTable(sql, parameters.ToArray());
}
}
public virtual async Task<DataTable> GetDataTableAsync(string sql, params SugarParameter[] parameters)
{
var ds =await GetDataSetAllAsync(sql, parameters);
if (ds.Tables.Count != 0 && ds.Tables.Count > 0) return ds.Tables[0];
return new DataTable();
}
public virtual Task<DataTable> GetDataTableAsync(string sql, object parameters)
{
return GetDataTableAsync(sql, this.GetParameters(parameters));
}
public virtual Task<DataTable> GetDataTableAsync(string sql, List<SugarParameter> parameters)
{
if (parameters == null)
{
return GetDataTableAsync(sql);
}
else
{
return GetDataTableAsync(sql, parameters.ToArray());
}
}
public virtual DataSet GetDataSetAll(string sql, object parameters)
{
return GetDataSetAll(sql, this.GetParameters(parameters));
@ -1250,6 +1405,26 @@ namespace SqlSugar
return GetDataSetAll(sql, parameters.ToArray());
}
}
public virtual Task<DataSet> GetDataSetAllAsync(string sql, object parameters)
{
return GetDataSetAllAsync(sql, this.GetParameters(parameters));
}
public virtual Task<DataSet> GetDataSetAllAsync(string sql, List<SugarParameter> parameters)
{
if (parameters == null)
{
return GetDataSetAllAsync(sql);
}
else
{
return GetDataSetAllAsync(sql, parameters.ToArray());
}
}
public virtual IDataReader GetDataReader(string sql, object parameters)
{
return GetDataReader(sql, this.GetParameters(parameters));
@ -1536,5 +1711,26 @@ namespace SqlSugar
}
}
#endregion
#region Obsolete
[Obsolete]
public virtual dynamic SqlQueryDynamic(string sql, object parameters = null)
{
var dt = this.GetDataTable(sql, parameters);
return dt == null ? null : this.Context.Utilities.DataTableToDynamic(dt);
}
[Obsolete]
public virtual dynamic SqlQueryDynamic(string sql, params SugarParameter[] parameters)
{
var dt = this.GetDataTable(sql, parameters);
return dt == null ? null : this.Context.Utilities.DataTableToDynamic(dt);
}
[Obsolete]
public dynamic SqlQueryDynamic(string sql, List<SugarParameter> parameters)
{
var dt = this.GetDataTable(sql, parameters);
return dt == null ? null : this.Context.Utilities.DataTableToDynamic(dt);
}
#endregion
}
}

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

@ -33,17 +33,29 @@ namespace SqlSugar
void SetCommandToAdapter(IDataAdapter adapter, DbCommand command);
IDataAdapter GetAdapter();
DbCommand GetCommand(string sql, SugarParameter[] parameters);
DataTable GetDataTable(string sql, object parameters);
DataTable GetDataTable(string sql, params SugarParameter[] parameters);
DataTable GetDataTable(string sql, List<SugarParameter> parameters);
Task<DataTable> GetDataTableAsync(string sql, object parameters);
Task<DataTable> GetDataTableAsync(string sql, params SugarParameter[] parameters);
Task<DataTable> GetDataTableAsync(string sql, List<SugarParameter> parameters);
DataSet GetDataSetAll(string sql, object parameters);
DataSet GetDataSetAll(string sql, params SugarParameter[] parameters);
DataSet GetDataSetAll(string sql, List<SugarParameter> parameters);
Task<DataSet> GetDataSetAllAsync(string sql, object parameters);
Task<DataSet> GetDataSetAllAsync(string sql, params SugarParameter[] parameters);
Task<DataSet> GetDataSetAllAsync(string sql, List<SugarParameter> parameters);
IDataReader GetDataReader(string sql, object parameters);
IDataReader GetDataReader(string sql, params SugarParameter[] parameters);
IDataReader GetDataReader(string sql, List<SugarParameter> parameters);
Task<IDataReader> GetDataReaderAsync(string sql, object parameters);
Task<IDataReader> GetDataReaderAsync(string sql, params SugarParameter[] parameters);
Task<IDataReader> GetDataReaderAsync(string sql, List<SugarParameter> parameters);
@ -68,17 +80,44 @@ namespace SqlSugar
string GetString(string sql, object parameters);
string GetString(string sql, params SugarParameter[] parameters);
string GetString(string sql, List<SugarParameter> parameters);
Task<string> GetStringAsync(string sql, object parameters);
Task<string> GetStringAsync(string sql, params SugarParameter[] parameters);
Task<string> GetStringAsync(string sql, List<SugarParameter> parameters);
int GetInt(string sql, object pars);
Task<int> GetIntAsync(string sql, params SugarParameter[] parameters);
int GetInt(string sql, params SugarParameter[] parameters);
int GetInt(string sql, List<SugarParameter> parameters);
Task<int> GetIntAsync(string sql, object pars);
Task<int> GetIntAsync(string sql, params SugarParameter[] parameters);
Task<int> GetIntAsync(string sql, List<SugarParameter> parameters);
long GetLong(string sql, object pars);
Task<long> GetLongAsync(string sql, object pars);
Double GetDouble(string sql, object parameters);
Double GetDouble(string sql, params SugarParameter[] parameters);
Double GetDouble(string sql, List<SugarParameter> parameters);
Task<Double> GetDoubleAsync(string sql, object parameters);
Task<Double> GetDoubleAsync(string sql, params SugarParameter[] parameters);
Task<Double> GetDoubleAsync(string sql, List<SugarParameter> parameters);
decimal GetDecimal(string sql, object parameters);
decimal GetDecimal(string sql, params SugarParameter[] parameters);
decimal GetDecimal(string sql, List<SugarParameter> parameters);
Task<decimal> GetDecimalAsync(string sql, object parameters);
Task<decimal> GetDecimalAsync(string sql, params SugarParameter[] parameters);
Task<decimal> GetDecimalAsync(string sql, List<SugarParameter> parameters);
DateTime GetDateTime(string sql, object parameters);
DateTime GetDateTime(string sql, params SugarParameter[] parameters);
DateTime GetDateTime(string sql, List<SugarParameter> parameters);
@ -89,6 +128,7 @@ namespace SqlSugar
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>, List<T7>> SqlQuery<T, T2, T3, T4, T5, T6,T7>(string sql, object parameters = null);
Task<Tuple<List<T>, List<T2>>> SqlQueryAsync<T, T2>(string sql, object parameters = null);
Task<Tuple<List<T>, List<T2>, List<T3>>> SqlQueryAsync<T, T2, T3>(string sql, object parameters = null);
Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>>> SqlQueryAsync<T, T2, T3, T4>(string sql, object parameters = null);
@ -107,9 +147,12 @@ namespace SqlSugar
T SqlQuerySingle<T>(string sql, object whereObj = null);
T SqlQuerySingle<T>(string sql, params SugarParameter[] parameters);
T SqlQuerySingle<T>(string sql, List<SugarParameter> parameters);
dynamic SqlQueryDynamic(string sql, object whereObj = null);
dynamic SqlQueryDynamic(string sql, params SugarParameter[] parameters);
dynamic SqlQueryDynamic(string sql, List<SugarParameter> parameters);
Task<T> SqlQuerySingleAsync<T>(string sql, object whereObj = null);
Task<T> SqlQuerySingleAsync<T>(string sql, params SugarParameter[] parameters);
Task<T> SqlQuerySingleAsync<T>(string sql, List<SugarParameter> parameters);
void Dispose();
void Close();
void Open();
@ -126,9 +169,21 @@ namespace SqlSugar
DbResult<T> UseTran<T>(Func<T> action, Action<Exception> errorCallBack = null);
Task<DbResult<bool>> UseTranAsync(Action action, Action<Exception> errorCallBack = null);
Task<DbResult<T>> UseTranAsync<T>(Func<T> action, Action<Exception> errorCallBack = null);
IAdo UseStoredProcedure();
#region Obsolete
[Obsolete("Use db.ado.UseStoredProcedure().MethodName()")]
void UseStoredProcedure(Action action);
[Obsolete("Use db.ado.UseStoredProcedure().MethodName()")]
T UseStoredProcedure<T>(Func<T> action);
IAdo UseStoredProcedure();
[Obsolete("Use SqlQuery<dynamic>(sql)")]
dynamic SqlQueryDynamic(string sql, object whereObj = null);
[Obsolete("Use SqlQuery<dynamic>(sql)")]
dynamic SqlQueryDynamic(string sql, params SugarParameter[] parameters);
[Obsolete("Use SqlQuery<dynamic>(sql)")]
dynamic SqlQueryDynamic(string sql, List<SugarParameter> parameters);
#endregion
}
}

Loading…
Cancel
Save