mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-05-03 12:18:00 +08:00
Synchronous method
This commit is contained in:
parent
6cbe6d6ec7
commit
34070818a1
@ -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<bool> UpdateRangeAsync(List<T> updateObjs);
|
||||
Task<bool> UpdateRangeAsync(T[] updateObjs);
|
||||
|
||||
|
||||
|
||||
|
||||
Task<int> CountAsync(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken);
|
||||
Task<bool> DeleteAsync(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken);
|
||||
Task<bool> DeleteAsync(T deleteObj, CancellationToken cancellationToken);
|
||||
Task<bool> DeleteAsync(List<T> deleteObjs, CancellationToken cancellationToken);
|
||||
Task<bool> DeleteByIdAsync(dynamic id, CancellationToken cancellationToken);
|
||||
Task<bool> DeleteByIdsAsync(dynamic[] ids, CancellationToken cancellationToken);
|
||||
Task<T> GetByIdAsync(dynamic id, CancellationToken cancellationToken);
|
||||
Task<List<T>> GetListAsync( CancellationToken cancellationToken);
|
||||
Task<List<T>> GetListAsync(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken);
|
||||
Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, PageModel page, CancellationToken cancellationToken);
|
||||
Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc, CancellationToken cancellationToken=default);
|
||||
Task<List<T>> GetPageListAsync(List<IConditionalModel> conditionalList, PageModel page, CancellationToken cancellationToken);
|
||||
Task<List<T>> GetPageListAsync(List<IConditionalModel> conditionalList, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc, CancellationToken cancellationToken=default);
|
||||
Task<T> GetSingleAsync(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken);
|
||||
Task<T> GetFirstAsync(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken);
|
||||
Task<bool> InsertAsync(T insertObj, CancellationToken cancellationToken);
|
||||
Task<bool> InsertOrUpdateAsync(T data, CancellationToken cancellationToken);
|
||||
Task<bool> InsertOrUpdateAsync(List<T> datas, CancellationToken cancellationToken);
|
||||
Task<bool> InsertRangeAsync(List<T> insertObjs, CancellationToken cancellationToken);
|
||||
Task<bool> InsertRangeAsync(T[] insertObjs, CancellationToken cancellationToken);
|
||||
Task<int> InsertReturnIdentityAsync(T insertObj, CancellationToken cancellationToken);
|
||||
Task<long> InsertReturnBigIdentityAsync(T insertObj, CancellationToken cancellationToken);
|
||||
Task<long> InsertReturnSnowflakeIdAsync(T insertObj, CancellationToken cancellationToken);
|
||||
Task<List<long>> InsertReturnSnowflakeIdAsync(List<T> insertObjs, CancellationToken cancellationToken);
|
||||
Task<T> InsertReturnEntityAsync(T insertObj, CancellationToken cancellationToken);
|
||||
|
||||
Task<bool> IsAnyAsync(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken);
|
||||
Task<bool> UpdateSetColumnsTrueAsync(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken);
|
||||
Task<bool> UpdateAsync(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken);
|
||||
Task<bool> UpdateAsync(T updateObj, CancellationToken cancellationToken);
|
||||
Task<bool> UpdateRangeAsync(List<T> updateObjs, CancellationToken cancellationToken);
|
||||
Task<bool> UpdateRangeAsync(T[] updateObjs, CancellationToken cancellationToken);
|
||||
|
||||
}
|
||||
}
|
@ -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<T>().In(ids).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Async Method CancellationToken
|
||||
public virtual Task<long> InsertReturnSnowflakeIdAsync(T insertObj, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return this.Context.Insertable(insertObj).ExecuteReturnSnowflakeIdAsync();
|
||||
}
|
||||
public virtual Task<List<long>> InsertReturnSnowflakeIdAsync(List<T> insertObjs, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return this.Context.Insertable(insertObjs).ExecuteReturnSnowflakeIdListAsync();
|
||||
}
|
||||
|
||||
public virtual Task<T> GetByIdAsync(dynamic id,CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken= cancellationToken;
|
||||
return Context.Queryable<T>().InSingleAsync(id);
|
||||
}
|
||||
public virtual Task<List<T>> GetListAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return Context.Queryable<T>().ToListAsync();
|
||||
}
|
||||
|
||||
public virtual Task<List<T>> GetListAsync(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return Context.Queryable<T>().Where(whereExpression).ToListAsync();
|
||||
}
|
||||
public virtual Task<T> GetSingleAsync(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return Context.Queryable<T>().SingleAsync(whereExpression);
|
||||
}
|
||||
public virtual Task<T> GetFirstAsync(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return Context.Queryable<T>().FirstAsync(whereExpression);
|
||||
}
|
||||
public virtual async Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, PageModel page, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
RefAsync<int> count = 0;
|
||||
var result = await Context.Queryable<T>().Where(whereExpression).ToPageListAsync(page.PageIndex, page.PageSize, count);
|
||||
page.TotalCount = count;
|
||||
return result;
|
||||
}
|
||||
public virtual async Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc, CancellationToken cancellationToken = default)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
RefAsync<int> count = 0;
|
||||
var result = await Context.Queryable<T>().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(whereExpression).ToPageListAsync(page.PageIndex, page.PageSize, count);
|
||||
page.TotalCount = count;
|
||||
return result;
|
||||
}
|
||||
public virtual async Task<List<T>> GetPageListAsync(List<IConditionalModel> conditionalList, PageModel page, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
RefAsync<int> count = 0;
|
||||
var result = await Context.Queryable<T>().Where(conditionalList).ToPageListAsync(page.PageIndex, page.PageSize, count);
|
||||
page.TotalCount = count;
|
||||
return result;
|
||||
}
|
||||
public virtual async Task<List<T>> GetPageListAsync(List<IConditionalModel> conditionalList, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc, CancellationToken cancellationToken=default)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
RefAsync<int> count = 0;
|
||||
var result = await Context.Queryable<T>().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(conditionalList).ToPageListAsync(page.PageIndex, page.PageSize, count);
|
||||
page.TotalCount = count;
|
||||
return result;
|
||||
}
|
||||
public virtual Task<bool> IsAnyAsync(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return Context.Queryable<T>().Where(whereExpression).AnyAsync();
|
||||
}
|
||||
public virtual Task<int> CountAsync(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return Context.Queryable<T>().Where(whereExpression).CountAsync();
|
||||
}
|
||||
|
||||
public virtual async Task<bool> InsertOrUpdateAsync(T data, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return await this.Context.Storageable(data).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
public virtual async Task<bool> InsertOrUpdateAsync(List<T> datas, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return await this.Context.Storageable(datas).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
public virtual async Task<bool> InsertAsync(T insertObj, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return await this.Context.Insertable(insertObj).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
public virtual Task<int> InsertReturnIdentityAsync(T insertObj, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return this.Context.Insertable(insertObj).ExecuteReturnIdentityAsync();
|
||||
}
|
||||
public virtual Task<long> InsertReturnBigIdentityAsync(T insertObj, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return this.Context.Insertable(insertObj).ExecuteReturnBigIdentityAsync();
|
||||
}
|
||||
public virtual async Task<T> InsertReturnEntityAsync(T insertObj, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return await this.Context.Insertable(insertObj).ExecuteReturnEntityAsync();
|
||||
}
|
||||
public virtual async Task<bool> InsertRangeAsync(T[] insertObjs, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return await this.Context.Insertable(insertObjs).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
public virtual async Task<bool> InsertRangeAsync(List<T> insertObjs, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return await this.Context.Insertable(insertObjs).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
public virtual async Task<bool> UpdateAsync(T updateObj, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return await this.Context.Updateable(updateObj).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
public virtual async Task<bool> UpdateRangeAsync(T[] updateObjs, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return await this.Context.Updateable(updateObjs).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
public virtual async Task<bool> UpdateRangeAsync(List<T> updateObjs, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return await this.Context.Updateable(updateObjs).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
public virtual async Task<bool> UpdateAsync(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return await this.Context.Updateable<T>().SetColumns(columns).Where(whereExpression).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
public virtual async Task<bool> UpdateSetColumnsTrueAsync(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return await this.Context.Updateable<T>().SetColumns(columns, true).Where(whereExpression).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
public virtual async Task<bool> DeleteAsync(T deleteObj, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return await this.Context.Deleteable<T>().Where(deleteObj).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
public virtual async Task<bool> DeleteAsync(List<T> deleteObjs, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return await this.Context.Deleteable<T>().Where(deleteObjs).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
public virtual async Task<bool> DeleteAsync(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return await this.Context.Deleteable<T>().Where(whereExpression).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
public virtual async Task<bool> DeleteByIdAsync(dynamic id, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return await this.Context.Deleteable<T>().In(id).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
public virtual async Task<bool> DeleteByIdsAsync(dynamic[] ids, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return await this.Context.Deleteable<T>().In(ids).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user