diff --git a/Src/Asp.NetCore2/SqlSugar/Interface/ISimpleClient.cs b/Src/Asp.NetCore2/SqlSugar/Interface/ISimpleClient.cs index 467dc3e97..14093c056 100644 --- a/Src/Asp.NetCore2/SqlSugar/Interface/ISimpleClient.cs +++ b/Src/Asp.NetCore2/SqlSugar/Interface/ISimpleClient.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace SqlSugar @@ -92,5 +93,41 @@ namespace SqlSugar Task UpdateRangeAsync(List updateObjs); Task UpdateRangeAsync(T[] updateObjs); + + + + Task CountAsync(Expression> whereExpression, CancellationToken cancellationToken); + Task DeleteAsync(Expression> whereExpression, CancellationToken cancellationToken); + Task DeleteAsync(T deleteObj, CancellationToken cancellationToken); + Task DeleteAsync(List deleteObjs, CancellationToken cancellationToken); + Task DeleteByIdAsync(dynamic id, CancellationToken cancellationToken); + Task DeleteByIdsAsync(dynamic[] ids, CancellationToken cancellationToken); + Task GetByIdAsync(dynamic id, CancellationToken cancellationToken); + Task> GetListAsync( CancellationToken cancellationToken); + Task> GetListAsync(Expression> whereExpression, CancellationToken cancellationToken); + Task> GetPageListAsync(Expression> whereExpression, PageModel page, CancellationToken cancellationToken); + Task> GetPageListAsync(Expression> whereExpression, PageModel page, Expression> orderByExpression = null, OrderByType orderByType = OrderByType.Asc, CancellationToken cancellationToken=default); + Task> GetPageListAsync(List conditionalList, PageModel page, CancellationToken cancellationToken); + Task> GetPageListAsync(List conditionalList, PageModel page, Expression> orderByExpression = null, OrderByType orderByType = OrderByType.Asc, CancellationToken cancellationToken=default); + Task GetSingleAsync(Expression> whereExpression, CancellationToken cancellationToken); + Task GetFirstAsync(Expression> whereExpression, CancellationToken cancellationToken); + Task InsertAsync(T insertObj, CancellationToken cancellationToken); + Task InsertOrUpdateAsync(T data, CancellationToken cancellationToken); + Task InsertOrUpdateAsync(List datas, CancellationToken cancellationToken); + Task InsertRangeAsync(List insertObjs, CancellationToken cancellationToken); + Task InsertRangeAsync(T[] insertObjs, CancellationToken cancellationToken); + Task InsertReturnIdentityAsync(T insertObj, CancellationToken cancellationToken); + Task InsertReturnBigIdentityAsync(T insertObj, CancellationToken cancellationToken); + Task InsertReturnSnowflakeIdAsync(T insertObj, CancellationToken cancellationToken); + Task> InsertReturnSnowflakeIdAsync(List insertObjs, CancellationToken cancellationToken); + Task InsertReturnEntityAsync(T insertObj, CancellationToken cancellationToken); + + Task IsAnyAsync(Expression> whereExpression, CancellationToken cancellationToken); + Task UpdateSetColumnsTrueAsync(Expression> columns, Expression> whereExpression, CancellationToken cancellationToken); + Task UpdateAsync(Expression> columns, Expression> whereExpression, CancellationToken cancellationToken); + Task UpdateAsync(T updateObj, CancellationToken cancellationToken); + Task UpdateRangeAsync(List updateObjs, CancellationToken cancellationToken); + Task UpdateRangeAsync(T[] updateObjs, CancellationToken cancellationToken); + } } \ No newline at end of file diff --git a/Src/Asp.NetCore2/SqlSugar/SimpleClient.cs b/Src/Asp.NetCore2/SqlSugar/SimpleClient.cs index 9ab529a1b..bb30d331d 100644 --- a/Src/Asp.NetCore2/SqlSugar/SimpleClient.cs +++ b/Src/Asp.NetCore2/SqlSugar/SimpleClient.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Text; +using System.Threading; using System.Threading.Tasks; namespace SqlSugar @@ -402,6 +403,179 @@ namespace SqlSugar return await this.Context.Deleteable().In(ids).ExecuteCommandAsync() > 0; } #endregion - + + #region Async Method CancellationToken + public virtual Task InsertReturnSnowflakeIdAsync(T insertObj, CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + return this.Context.Insertable(insertObj).ExecuteReturnSnowflakeIdAsync(); + } + public virtual Task> InsertReturnSnowflakeIdAsync(List insertObjs, CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + return this.Context.Insertable(insertObjs).ExecuteReturnSnowflakeIdListAsync(); + } + + public virtual Task GetByIdAsync(dynamic id,CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken= cancellationToken; + return Context.Queryable().InSingleAsync(id); + } + public virtual Task> GetListAsync(CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + return Context.Queryable().ToListAsync(); + } + + public virtual Task> GetListAsync(Expression> whereExpression, CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + return Context.Queryable().Where(whereExpression).ToListAsync(); + } + public virtual Task GetSingleAsync(Expression> whereExpression, CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + return Context.Queryable().SingleAsync(whereExpression); + } + public virtual Task GetFirstAsync(Expression> whereExpression, CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + return Context.Queryable().FirstAsync(whereExpression); + } + public virtual async Task> GetPageListAsync(Expression> whereExpression, PageModel page, CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + RefAsync count = 0; + var result = await Context.Queryable().Where(whereExpression).ToPageListAsync(page.PageIndex, page.PageSize, count); + page.TotalCount = count; + return result; + } + public virtual async Task> GetPageListAsync(Expression> whereExpression, PageModel page, Expression> orderByExpression = null, OrderByType orderByType = OrderByType.Asc, CancellationToken cancellationToken = default) + { + this.Context.Ado.CancellationToken = cancellationToken; + RefAsync count = 0; + var result = await Context.Queryable().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(whereExpression).ToPageListAsync(page.PageIndex, page.PageSize, count); + page.TotalCount = count; + return result; + } + public virtual async Task> GetPageListAsync(List conditionalList, PageModel page, CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + RefAsync count = 0; + var result = await Context.Queryable().Where(conditionalList).ToPageListAsync(page.PageIndex, page.PageSize, count); + page.TotalCount = count; + return result; + } + public virtual async Task> GetPageListAsync(List conditionalList, PageModel page, Expression> orderByExpression = null, OrderByType orderByType = OrderByType.Asc, CancellationToken cancellationToken=default) + { + this.Context.Ado.CancellationToken = cancellationToken; + RefAsync count = 0; + var result = await Context.Queryable().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(conditionalList).ToPageListAsync(page.PageIndex, page.PageSize, count); + page.TotalCount = count; + return result; + } + public virtual Task IsAnyAsync(Expression> whereExpression, CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + return Context.Queryable().Where(whereExpression).AnyAsync(); + } + public virtual Task CountAsync(Expression> whereExpression, CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + return Context.Queryable().Where(whereExpression).CountAsync(); + } + + public virtual async Task InsertOrUpdateAsync(T data, CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + return await this.Context.Storageable(data).ExecuteCommandAsync() > 0; + } + public virtual async Task InsertOrUpdateAsync(List datas, CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + return await this.Context.Storageable(datas).ExecuteCommandAsync() > 0; + } + public virtual async Task InsertAsync(T insertObj, CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + return await this.Context.Insertable(insertObj).ExecuteCommandAsync() > 0; + } + public virtual Task InsertReturnIdentityAsync(T insertObj, CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + return this.Context.Insertable(insertObj).ExecuteReturnIdentityAsync(); + } + public virtual Task InsertReturnBigIdentityAsync(T insertObj, CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + return this.Context.Insertable(insertObj).ExecuteReturnBigIdentityAsync(); + } + public virtual async Task InsertReturnEntityAsync(T insertObj, CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + return await this.Context.Insertable(insertObj).ExecuteReturnEntityAsync(); + } + public virtual async Task InsertRangeAsync(T[] insertObjs, CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + return await this.Context.Insertable(insertObjs).ExecuteCommandAsync() > 0; + } + public virtual async Task InsertRangeAsync(List insertObjs, CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + return await this.Context.Insertable(insertObjs).ExecuteCommandAsync() > 0; + } + public virtual async Task UpdateAsync(T updateObj, CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + return await this.Context.Updateable(updateObj).ExecuteCommandAsync() > 0; + } + public virtual async Task UpdateRangeAsync(T[] updateObjs, CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + return await this.Context.Updateable(updateObjs).ExecuteCommandAsync() > 0; + } + public virtual async Task UpdateRangeAsync(List updateObjs, CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + return await this.Context.Updateable(updateObjs).ExecuteCommandAsync() > 0; + } + public virtual async Task UpdateAsync(Expression> columns, Expression> whereExpression, CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + return await this.Context.Updateable().SetColumns(columns).Where(whereExpression).ExecuteCommandAsync() > 0; + } + public virtual async Task UpdateSetColumnsTrueAsync(Expression> columns, Expression> whereExpression, CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + return await this.Context.Updateable().SetColumns(columns, true).Where(whereExpression).ExecuteCommandAsync() > 0; + } + public virtual async Task DeleteAsync(T deleteObj, CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + return await this.Context.Deleteable().Where(deleteObj).ExecuteCommandAsync() > 0; + } + public virtual async Task DeleteAsync(List deleteObjs, CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + return await this.Context.Deleteable().Where(deleteObjs).ExecuteCommandAsync() > 0; + } + public virtual async Task DeleteAsync(Expression> whereExpression, CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + return await this.Context.Deleteable().Where(whereExpression).ExecuteCommandAsync() > 0; + } + public virtual async Task DeleteByIdAsync(dynamic id, CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + return await this.Context.Deleteable().In(id).ExecuteCommandAsync() > 0; + } + public virtual async Task DeleteByIdsAsync(dynamic[] ids, CancellationToken cancellationToken) + { + this.Context.Ado.CancellationToken = cancellationToken; + return await this.Context.Deleteable().In(ids).ExecuteCommandAsync() > 0; + } + #endregion + } }