This commit is contained in:
sunkaixuan 2019-05-18 19:53:34 +08:00
parent 7ee7d89b60
commit d456d50b9d

View File

@ -51,29 +51,25 @@ namespace SqlSugar
} }
public virtual int ExecuteCommand() public virtual int ExecuteCommand()
{ {
PreToSql(); string sql = _ExecuteCommand();
AutoRemoveDataCache();
Check.Exception(UpdateBuilder.WhereValues.IsNullOrEmpty() && GetPrimaryKeys().IsNullOrEmpty(), "You cannot have no primary key and no conditions");
string sql = UpdateBuilder.ToSqlString();
ValidateVersion();
RestoreMapping();
Before(sql);
var result = this.Ado.ExecuteCommand(sql, UpdateBuilder.Parameters == null ? null : UpdateBuilder.Parameters.ToArray()); var result = this.Ado.ExecuteCommand(sql, UpdateBuilder.Parameters == null ? null : UpdateBuilder.Parameters.ToArray());
After(sql); After(sql);
return result; return result;
} }
public bool ExecuteCommandHasChange() public bool ExecuteCommandHasChange()
{ {
return this.ExecuteCommand() > 0; return this.ExecuteCommand() > 0;
} }
public Task<int> ExecuteCommandAsync() public async Task<int> ExecuteCommandAsync()
{ {
return Task.FromResult(ExecuteCommand()); string sql = _ExecuteCommand();
var result =await this.Ado.ExecuteCommandAsync(sql, UpdateBuilder.Parameters == null ? null : UpdateBuilder.Parameters.ToArray());
After(sql);
return result;
} }
public Task<bool> ExecuteCommandHasChangeAsync() public async Task<bool> ExecuteCommandHasChangeAsync()
{ {
return Task.FromResult(ExecuteCommandHasChange()); return await this.ExecuteCommandAsync() > 0;
} }
#endregion #endregion
@ -374,6 +370,17 @@ namespace SqlSugar
#endregion #endregion
#region Helper #region Helper
private string _ExecuteCommand()
{
PreToSql();
AutoRemoveDataCache();
Check.Exception(UpdateBuilder.WhereValues.IsNullOrEmpty() && GetPrimaryKeys().IsNullOrEmpty(), "You cannot have no primary key and no conditions");
string sql = UpdateBuilder.ToSqlString();
ValidateVersion();
RestoreMapping();
Before(sql);
return sql;
}
private void AutoRemoveDataCache() private void AutoRemoveDataCache()
{ {
var moreSetts = this.Context.CurrentConnectionConfig.MoreSettings; var moreSetts = this.Context.CurrentConnectionConfig.MoreSettings;