This commit is contained in:
sunkaixuan
2017-12-19 17:12:25 +08:00
parent 21b39d7756
commit f6322e0187
3 changed files with 35 additions and 1 deletions

View File

@@ -28,6 +28,7 @@ namespace SqlSugar
string sql = DeleteBuilder.ToSqlString();
var paramters = DeleteBuilder.Parameters == null ? null : DeleteBuilder.Parameters.ToArray();
RestoreMapping();
AutoRemoveDataCache();
return Db.ExecuteCommand(sql, paramters);
}
public bool ExecuteCommandHasChange()
@@ -270,6 +271,17 @@ namespace SqlSugar
}
}
private void AutoRemoveDataCache()
{
var moreSetts = this.Context.CurrentConnectionConfig.MoreSettings;
var extService = this.Context.CurrentConnectionConfig.ConfigureExternalServices;
if (moreSetts != null && moreSetts.IsAutoRemoveDataCache && extService != null && extService.DataInfoCacheService != null)
{
this.RemoveDataCache();
}
}
private IDeleteable<T> CopyDeleteable()
{
var asyncContext = this.Context.Utilities.CopyContext(true);

View File

@@ -32,6 +32,7 @@ namespace SqlSugar
{
InsertBuilder.IsReturnIdentity = false;
PreToSql();
AutoRemoveDataCache();
string sql = InsertBuilder.ToSqlString();
RestoreMapping();
return Ado.ExecuteCommand(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
@@ -41,6 +42,7 @@ namespace SqlSugar
{
InsertBuilder.IsReturnIdentity = true;
PreToSql();
AutoRemoveDataCache();
string sql = InsertBuilder.ToSqlString();
RestoreMapping();
return new KeyValuePair<string, List<SugarParameter>>(sql, InsertBuilder.Parameters);
@@ -49,6 +51,7 @@ namespace SqlSugar
{
InsertBuilder.IsReturnIdentity = true;
PreToSql();
AutoRemoveDataCache();
string sql = InsertBuilder.ToSqlString();
RestoreMapping();
return Ado.GetInt(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
@@ -57,6 +60,7 @@ namespace SqlSugar
{
InsertBuilder.IsReturnIdentity = true;
PreToSql();
AutoRemoveDataCache();
string sql = InsertBuilder.ToSqlString();
RestoreMapping();
return Convert.ToInt64( Ado.GetScalar(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()));
@@ -194,6 +198,15 @@ namespace SqlSugar
#endregion
#region Protected Methods
private void AutoRemoveDataCache()
{
var moreSetts = this.Context.CurrentConnectionConfig.MoreSettings;
var extService = this.Context.CurrentConnectionConfig.ConfigureExternalServices;
if (moreSetts != null && moreSetts.IsAutoRemoveDataCache && extService != null && extService.DataInfoCacheService != null)
{
this.RemoveDataCache();
}
}
protected virtual void PreToSql()
{
#region Identities

View File

@@ -28,6 +28,7 @@ namespace SqlSugar
public virtual int ExecuteCommand()
{
PreToSql();
AutoRemoveDataCache();
Check.Exception(UpdateBuilder.WhereValues.IsNullOrEmpty() && GetPrimaryKeys().IsNullOrEmpty(), "You cannot have no primary key and no conditions");
string sql = UpdateBuilder.ToSqlString();
RestoreMapping();
@@ -93,7 +94,15 @@ namespace SqlSugar
UpdateBuilder.SetValues.Add(new KeyValuePair<string, string>(leftResultString, resultString));
return this;
}
private void AutoRemoveDataCache()
{
var moreSetts = this.Context.CurrentConnectionConfig.MoreSettings;
var extService = this.Context.CurrentConnectionConfig.ConfigureExternalServices;
if (moreSetts != null && moreSetts.IsAutoRemoveDataCache && extService!=null&& extService.DataInfoCacheService!=null)
{
this.RemoveDataCache();
}
}
public KeyValuePair<string, List<SugarParameter>> ToSql()
{
PreToSql();