mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
-
This commit is contained in:
parent
5cd83c7f8b
commit
fdea70d3d9
@ -28,6 +28,10 @@ namespace OrmTest.Demo
|
||||
|
||||
//by expression id>1 and id==1
|
||||
var t5 = db.Deleteable<Student>().Where(it => it.Id > 1).Where(it => it.Id == 1).ExecuteCommand();
|
||||
|
||||
var t6 = db.Deleteable<Student>().AS("student").Where(it => it.Id > 1).Where(it => it.Id == 1).ExecuteCommandAsync();
|
||||
t6.Start();
|
||||
t6.Wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,15 @@ namespace SqlSugar
|
||||
RestoreMapping();
|
||||
return Db.ExecuteCommand(sql, paramters);
|
||||
}
|
||||
public Task<int> ExecuteCommandAsync()
|
||||
{
|
||||
Task<int> result = new Task<int>(() =>
|
||||
{
|
||||
IDeleteable<T> asyncDeleteable = CopyDeleteable();
|
||||
return asyncDeleteable.ExecuteCommand();
|
||||
});
|
||||
return result;
|
||||
}
|
||||
public IDeleteable<T> AS(string tableName)
|
||||
{
|
||||
var entityName = typeof(T).Name;
|
||||
@ -206,7 +215,6 @@ namespace SqlSugar
|
||||
return new KeyValuePair<string, List<SugarParameter>>(sql, paramters);
|
||||
}
|
||||
|
||||
|
||||
private List<string> GetPrimaryKeys()
|
||||
{
|
||||
if (this.Context.IsSystemTablesConfig)
|
||||
@ -218,6 +226,7 @@ namespace SqlSugar
|
||||
return this.EntityInfo.Columns.Where(it => it.IsPrimarykey).Select(it => it.DbColumnName).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
private List<string> GetIdentityKeys()
|
||||
{
|
||||
if (this.Context.IsSystemTablesConfig)
|
||||
@ -229,6 +238,7 @@ namespace SqlSugar
|
||||
return this.EntityInfo.Columns.Where(it => it.IsIdentity).Select(it => it.DbColumnName).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
private void RestoreMapping()
|
||||
{
|
||||
if (IsAs)
|
||||
@ -236,5 +246,24 @@ namespace SqlSugar
|
||||
this.Context.MappingTables = OldMappingTableList;
|
||||
}
|
||||
}
|
||||
|
||||
private IDeleteable<T> CopyDeleteable() {
|
||||
var asyncContext = this.Context.CopyContext(this.Context.RewritableMethods.TranslateCopy(this.Context.CurrentConnectionConfig));
|
||||
asyncContext.CurrentConnectionConfig.IsAutoCloseConnection = true;
|
||||
asyncContext.Ado.IsEnableLogEvent = this.Context.Ado.IsEnableLogEvent;
|
||||
asyncContext.Ado.LogEventStarting = this.Context.Ado.LogEventStarting;
|
||||
asyncContext.Ado.LogEventCompleted = this.Context.Ado.LogEventCompleted;
|
||||
asyncContext.Ado.ProcessingEventStartingSQL = this.Context.Ado.ProcessingEventStartingSQL;
|
||||
|
||||
var asyncDeleteable = asyncContext.Deleteable<T>();
|
||||
var asyncDeleteBuilder = asyncDeleteable.DeleteBuilder;
|
||||
asyncDeleteBuilder.BigDataFiled = this.DeleteBuilder.BigDataFiled;
|
||||
asyncDeleteBuilder.BigDataInValues = this.DeleteBuilder.BigDataInValues;
|
||||
asyncDeleteBuilder.Parameters = this.DeleteBuilder.Parameters;
|
||||
asyncDeleteBuilder.sql = this.DeleteBuilder.sql;
|
||||
asyncDeleteBuilder.WhereInfos = this.DeleteBuilder.WhereInfos;
|
||||
asyncDeleteBuilder.TableWithString = this.DeleteBuilder.TableWithString;
|
||||
return asyncDeleteable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,8 +37,8 @@ namespace SqlSugar
|
||||
{
|
||||
Task<int> result = new Task<int>(() =>
|
||||
{
|
||||
IUpdateable<T> asyncInsertable = CopyUpdateable();
|
||||
return asyncInsertable.ExecuteCommand();
|
||||
IUpdateable<T> asyncUpdateable = CopyUpdateable();
|
||||
return asyncUpdateable.ExecuteCommand();
|
||||
});
|
||||
return result;
|
||||
}
|
||||
@ -318,17 +318,17 @@ namespace SqlSugar
|
||||
asyncContext.Ado.ProcessingEventStartingSQL = this.Context.Ado.ProcessingEventStartingSQL;
|
||||
|
||||
var asyncUpdateable = asyncContext.Updateable<T>(this.UpdateObjs);
|
||||
var asyncInsertableBuilder = asyncUpdateable.UpdateBuilder;
|
||||
asyncInsertableBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList;
|
||||
asyncInsertableBuilder.IsNoUpdateNull = this.UpdateBuilder.IsNoUpdateNull;
|
||||
asyncInsertableBuilder.Parameters = this.UpdateBuilder.Parameters;
|
||||
asyncInsertableBuilder.sql = this.UpdateBuilder.sql;
|
||||
asyncInsertableBuilder.WhereValues = this.UpdateBuilder.WhereValues;
|
||||
asyncInsertableBuilder.TableWithString = this.UpdateBuilder.TableWithString;
|
||||
asyncInsertableBuilder.TableName = this.UpdateBuilder.TableName;
|
||||
asyncInsertableBuilder.PrimaryKeys = this.UpdateBuilder.PrimaryKeys;
|
||||
asyncInsertableBuilder.IsOffIdentity = this.UpdateBuilder.IsOffIdentity;
|
||||
asyncInsertableBuilder.SetValues = this.UpdateBuilder.SetValues;
|
||||
var asyncUpdateableBuilder = asyncUpdateable.UpdateBuilder;
|
||||
asyncUpdateableBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList;
|
||||
asyncUpdateableBuilder.IsNoUpdateNull = this.UpdateBuilder.IsNoUpdateNull;
|
||||
asyncUpdateableBuilder.Parameters = this.UpdateBuilder.Parameters;
|
||||
asyncUpdateableBuilder.sql = this.UpdateBuilder.sql;
|
||||
asyncUpdateableBuilder.WhereValues = this.UpdateBuilder.WhereValues;
|
||||
asyncUpdateableBuilder.TableWithString = this.UpdateBuilder.TableWithString;
|
||||
asyncUpdateableBuilder.TableName = this.UpdateBuilder.TableName;
|
||||
asyncUpdateableBuilder.PrimaryKeys = this.UpdateBuilder.PrimaryKeys;
|
||||
asyncUpdateableBuilder.IsOffIdentity = this.UpdateBuilder.IsOffIdentity;
|
||||
asyncUpdateableBuilder.SetValues = this.UpdateBuilder.SetValues;
|
||||
return asyncUpdateable;
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,9 @@ namespace SqlSugar
|
||||
{
|
||||
public interface IDeleteable<T> where T : class, new()
|
||||
{
|
||||
DeleteBuilder DeleteBuilder { get; set; }
|
||||
int ExecuteCommand();
|
||||
Task<int> ExecuteCommandAsync();
|
||||
IDeleteable<T> AS(string tableName);
|
||||
IDeleteable<T> With(string lockString);
|
||||
IDeleteable<T> Where(T deleteObj);
|
||||
|
Loading…
Reference in New Issue
Block a user