diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/AdoProvider/AdoProvider.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/AdoProvider/AdoProvider.cs index 196da4339..e90eb2183 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/AdoProvider/AdoProvider.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/AdoProvider/AdoProvider.cs @@ -31,6 +31,7 @@ namespace SqlSugar #endregion #region Properties + internal bool IsOpenAsync { get; set; } protected List OutputParameters { get; set; } public virtual string SqlParameterKeyWord { get { return "@"; } } public IDbTransaction Transaction { get; set; } @@ -626,7 +627,7 @@ namespace SqlSugar if (this.ProcessingEventStartingSQL != null) ExecuteProcessingSQL(ref sql,ref parameters); ExecuteBefore(sql, parameters); - var sqlCommand = GetCommand(sql, parameters); + var sqlCommand =IsOpenAsync? await GetCommandAsync(sql, parameters) : GetCommand(sql, parameters); int count; if (this.CancellationToken == null) count=await sqlCommand.ExecuteNonQueryAsync(); @@ -668,7 +669,7 @@ namespace SqlSugar if (this.ProcessingEventStartingSQL != null) ExecuteProcessingSQL(ref sql,ref parameters); ExecuteBefore(sql, parameters); - var sqlCommand = GetCommand(sql, parameters); + var sqlCommand = IsOpenAsync ? await GetCommandAsync(sql, parameters) : GetCommand(sql, parameters); DbDataReader sqlDataReader; if(this.CancellationToken==null) sqlDataReader=await sqlCommand.ExecuteReaderAsync(this.IsAutoClose() ? CommandBehavior.CloseConnection : CommandBehavior.Default); @@ -707,7 +708,7 @@ namespace SqlSugar if (this.ProcessingEventStartingSQL != null) ExecuteProcessingSQL(ref sql,ref parameters); ExecuteBefore(sql, parameters); - var sqlCommand = GetCommand(sql, parameters); + var sqlCommand = IsOpenAsync ? await GetCommandAsync(sql, parameters) : GetCommand(sql, parameters); object scalar; if(CancellationToken==null) scalar=await sqlCommand.ExecuteScalarAsync(); @@ -1461,6 +1462,11 @@ namespace SqlSugar #endregion #region Helper + public virtual async Task GetCommandAsync(string sql, SugarParameter[] parameters) + { + await Task.FromResult(0); + throw new NotImplementedException(); + } public async Task CloseAsync() { if (this.Transaction != null) diff --git a/Src/Asp.NetCore2/SqlSugar/Realization/SqlServer/SqlServerProvider.cs b/Src/Asp.NetCore2/SqlSugar/Realization/SqlServer/SqlServerProvider.cs index dfc831053..517318b04 100644 --- a/Src/Asp.NetCore2/SqlSugar/Realization/SqlServer/SqlServerProvider.cs +++ b/Src/Asp.NetCore2/SqlSugar/Realization/SqlServer/SqlServerProvider.cs @@ -7,12 +7,16 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; +using System.Threading; namespace SqlSugar { public class SqlServerProvider : AdoProvider { - public SqlServerProvider() { } + + public SqlServerProvider() { + this.IsOpenAsync = true; + } public override IDbConnection Connection { get @@ -75,6 +79,23 @@ namespace SqlSugar CheckConnection(); return sqlCommand; } + public override async Task GetCommandAsync(string sql, SugarParameter[] parameters) + { + SqlCommand sqlCommand = new SqlCommand(sql, (SqlConnection)this.Connection); + sqlCommand.CommandType = this.CommandType; + sqlCommand.CommandTimeout = this.CommandTimeOut; + if (this.Transaction != null) + { + sqlCommand.Transaction = (SqlTransaction)this.Transaction; + } + if (parameters.HasValue()) + { + SqlParameter[] ipars = GetSqlParameter(parameters); + sqlCommand.Parameters.AddRange(ipars); + } + await CheckConnectionAsync(); + return sqlCommand; + } public override void SetCommandToAdapter(IDataAdapter dataAdapter, DbCommand command) { ((SqlDataAdapter)dataAdapter).SelectCommand = (SqlCommand)command;