|
|
|
@ -7,8 +7,6 @@ namespace Repository;
|
|
|
|
|
|
|
|
|
|
public abstract class BaseRepository<T> where T : class, new()
|
|
|
|
|
{
|
|
|
|
|
private readonly ISqlSugarClient DbBaseClient;
|
|
|
|
|
|
|
|
|
|
//private readonly IUnitOfWork _unitOfWork;
|
|
|
|
|
protected BaseRepository(ISqlSugarClient sqlSugar)
|
|
|
|
|
{
|
|
|
|
@ -16,6 +14,8 @@ public abstract class BaseRepository<T> where T : class, new()
|
|
|
|
|
DbBaseClient = sqlSugar;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ISqlSugarClient DbBaseClient;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据主值查询单条数据
|
|
|
|
|
/// </summary>
|
|
|
|
@ -33,7 +33,7 @@ public abstract class BaseRepository<T> where T : class, new()
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据主值查询单条数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="objId">id(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件</param>
|
|
|
|
|
/// <param name="objId">Id(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件</param>
|
|
|
|
|
/// <param name="blUseNoLock">是否使用WITH(NOLOCK)</param>
|
|
|
|
|
/// <returns>数据实体</returns>
|
|
|
|
|
public async Task<T> QueryByIdAsync(object objId, bool blUseNoLock = false)
|
|
|
|
@ -59,44 +59,6 @@ public abstract class BaseRepository<T> where T : class, new()
|
|
|
|
|
.WithNoLockOrNot(blUseNoLock)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
public async Task<List<T>> QueryPageAsync(
|
|
|
|
|
bool isWhere1, Expression<Func<T, bool>> expression1,
|
|
|
|
|
bool isWhere2, Expression<Func<T, bool>> expression2,
|
|
|
|
|
bool isWhere3, Expression<Func<T, bool>> expression3,
|
|
|
|
|
int pageNumber, int pageSize, RefAsync<int> totalNumber,
|
|
|
|
|
PageConfigReq input, bool blUseNoLock = false)
|
|
|
|
|
{
|
|
|
|
|
var page = await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.WhereIF(isWhere1, expression1)
|
|
|
|
|
.WhereIF(isWhere2, expression2)
|
|
|
|
|
.WhereIF(isWhere3, expression3)
|
|
|
|
|
.OrderBuilder(input)
|
|
|
|
|
.WithNoLockOrNot(blUseNoLock)
|
|
|
|
|
.ToPageListAsync(pageNumber, pageSize, totalNumber);
|
|
|
|
|
return page;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<int> UpdateAsync(T updateObj, bool ignoreAllNullColumns)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Updateable(updateObj)
|
|
|
|
|
.IgnoreColumns(ignoreAllNullColumns)
|
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<List<TResult>> QueryByGroupByAsync<TResult>(
|
|
|
|
|
Expression<Func<T, object>> expression,
|
|
|
|
|
Expression<Func<T, TResult>> expression2
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.GroupBy(expression)
|
|
|
|
|
.Select(expression2)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据主值列表查询单条数据
|
|
|
|
@ -128,6 +90,98 @@ public abstract class BaseRepository<T> where T : class, new()
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据条件查询表单数据(分页)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="page"> 页数</param>
|
|
|
|
|
/// <param name="pageSize">每页几条数据</param>
|
|
|
|
|
/// <param name="blUseNoLock">是否使用WITH(NOLOCK)</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public IPage<T> QueryIPageByCause(QueryPageModel page, Expression<Func<T, bool>> predicate)
|
|
|
|
|
{
|
|
|
|
|
if (null == predicate)
|
|
|
|
|
{
|
|
|
|
|
return this.QueryIPage(page);
|
|
|
|
|
}
|
|
|
|
|
int totalCount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<T> pageList = DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.Where(predicate)
|
|
|
|
|
.WithNoLockOrNot(false)
|
|
|
|
|
.ToPageList(page.Page, page.PageSize, ref totalCount);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new IPage<T>(totalCount, page, pageList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据条件查询表单数据(分页) 异步
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="page"></param>
|
|
|
|
|
/// <param name="predicate"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<IPage<T>> QueryIPageByCauseAsync(QueryPageModel page, Expression<Func<T, bool>> predicate)
|
|
|
|
|
{
|
|
|
|
|
if (null == predicate)
|
|
|
|
|
{
|
|
|
|
|
return await this.QueryIPageAsync(page);
|
|
|
|
|
}
|
|
|
|
|
RefAsync<int> totalCount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<T> pageList = await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.Where(predicate)
|
|
|
|
|
.WithNoLockOrNot(false)
|
|
|
|
|
.ToPageListAsync(page.Page, page.PageSize, totalCount);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new IPage<T>(totalCount, page, pageList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询表单所有数据(分页)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="page"> 页数</param>
|
|
|
|
|
/// <param name="pageSize">每页几条数据</param>
|
|
|
|
|
/// <param name="blUseNoLock">是否使用WITH(NOLOCK)</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public IPage<T> QueryIPage(QueryPageModel page)
|
|
|
|
|
{
|
|
|
|
|
int totalCount = 0;
|
|
|
|
|
//page.Page = page.Page == 0 ? 1 : page.Page;//默认第一页 10条数据
|
|
|
|
|
//page.PageSize = page.PageSize == 0 ? 10 : page.PageSize;
|
|
|
|
|
|
|
|
|
|
List<T> pageList = DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.WithNoLockOrNot(false)
|
|
|
|
|
.ToPageList(page.Page, page.PageSize, ref totalCount);
|
|
|
|
|
|
|
|
|
|
return new IPage<T>(totalCount, page, pageList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询表单所有数据(分页) 异步
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="page"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<IPage<T>> QueryIPageAsync(QueryPageModel page)
|
|
|
|
|
{
|
|
|
|
|
RefAsync<int> totalCount = 0;
|
|
|
|
|
|
|
|
|
|
List<T> pageList = await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.WithNoLockOrNot(false)
|
|
|
|
|
.ToPageListAsync(page.Page, page.PageSize, totalCount);
|
|
|
|
|
|
|
|
|
|
return new IPage<T>(totalCount, page, pageList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据主值列表查询单条数据
|
|
|
|
|
/// </summary>
|
|
|
|
@ -186,6 +240,7 @@ public abstract class BaseRepository<T> where T : class, new()
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据条件查询数据
|
|
|
|
|
/// </summary>
|
|
|
|
@ -203,6 +258,66 @@ public abstract class BaseRepository<T> where T : class, new()
|
|
|
|
|
.WithNoLockOrNot(blUseNoLock)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
public async Task<List<TResult>> QueryListByClauseAsync<TResult>(
|
|
|
|
|
bool isWhere, Expression<Func<T, bool>> expression,
|
|
|
|
|
Expression<Func<T, object>> orderBy,
|
|
|
|
|
bool blUseNoLock = false)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.OrderBy(orderBy, OrderByType.Asc)
|
|
|
|
|
.WhereIF(isWhere, expression)
|
|
|
|
|
.WithNoLockOrNot(blUseNoLock)
|
|
|
|
|
.Select<TResult>()
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<List<TResult>> QueryListByClauseAsync<TResult>(
|
|
|
|
|
Expression<Func<T, bool>> expression, Expression<Func<T, TResult>> expression1
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.Where(expression)
|
|
|
|
|
.ToListAsync(expression1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<List<TResult>> QueryListBySelectClauseAsync<TResult>(Expression<Func<T, TResult>> selectExpression)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.Select(selectExpression)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<List<T>> QueryListByOrderClauseAsync(Expression<Func<T, object>> expression)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.OrderBy(expression, OrderByType.Asc)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
public async Task<List<T>> QueryListByClauseAsync<TReturn1>(
|
|
|
|
|
Expression<Func<T, List<TReturn1>>> include1,
|
|
|
|
|
Expression<Func<T, object>> expression)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.Includes(include1)
|
|
|
|
|
.OrderBy(expression, OrderByType.Asc)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
public async Task<List<T>> QueryListByInludeClauseAsync<TReturn1>(
|
|
|
|
|
Expression<Func<T, TReturn1>> include1, Expression<Func<T, bool>> expression, Expression<Func<T, object>> expression2
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.Includes(include1)
|
|
|
|
|
.Where(expression)
|
|
|
|
|
.OrderBy(expression2, OrderByType.Asc)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据条件查询数据
|
|
|
|
@ -239,6 +354,89 @@ public abstract class BaseRepository<T> where T : class, new()
|
|
|
|
|
.WithNoLockOrNot(blUseNoLock)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
public async Task<List<T>> QueryListByClauseAsync(
|
|
|
|
|
bool isWhere, Expression<Func<T, bool>> expression,
|
|
|
|
|
bool isWhere1, Expression<Func<T, bool>> expression1,
|
|
|
|
|
bool isWhere2, Expression<Func<T, bool>> expression2,
|
|
|
|
|
Expression<Func<T, object>> expression3,
|
|
|
|
|
bool blUseNoLock = false)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.OrderBy(expression3, OrderByType.Asc)
|
|
|
|
|
.WhereIF(isWhere, expression)
|
|
|
|
|
.WhereIF(isWhere1, expression1)
|
|
|
|
|
.WhereIF(isWhere2, expression2)
|
|
|
|
|
.WithNoLockOrNot(blUseNoLock)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
public async Task<List<T>> QueryListByClauseAsync(
|
|
|
|
|
Expression<Func<T, bool>> expression,
|
|
|
|
|
bool isWhere1, Expression<Func<T, bool>> expression1,
|
|
|
|
|
bool isWhere2, Expression<Func<T, bool>> expression2,
|
|
|
|
|
Expression<Func<T, object>> expression3,
|
|
|
|
|
int pageNumber, int pageSize, RefAsync<int> totalNumber,
|
|
|
|
|
bool blUseNoLock = false)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.OrderBy(expression3, OrderByType.Asc)
|
|
|
|
|
.Where(expression)
|
|
|
|
|
.WhereIF(isWhere1, expression1)
|
|
|
|
|
.WhereIF(isWhere2, expression2)
|
|
|
|
|
.WithNoLockOrNot(blUseNoLock)
|
|
|
|
|
.ToPageListAsync(pageNumber, pageSize, totalNumber);
|
|
|
|
|
}
|
|
|
|
|
public async Task<List<T>> QueryTreeByClauseAsync(
|
|
|
|
|
Expression<Func<T, object>> expression,
|
|
|
|
|
Expression<Func<T, IEnumerable<object>>> childListExpression, Expression<Func<T, object>> parentIdExpression, object rootValue)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.OrderBy(expression, OrderByType.Asc)
|
|
|
|
|
.ToTreeAsync(childListExpression, parentIdExpression, rootValue);
|
|
|
|
|
}
|
|
|
|
|
public async Task<List<T>> QueryTreeByClauseAsync(
|
|
|
|
|
Expression<Func<T, object>> expression,
|
|
|
|
|
Expression<Func<T, IEnumerable<object>>> childListExpression, Expression<Func<T, object>> parentIdExpression, object rootValue, object[] childIds)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.OrderBy(expression, OrderByType.Asc)
|
|
|
|
|
.ToTreeAsync(childListExpression, parentIdExpression, rootValue, childIds);
|
|
|
|
|
}
|
|
|
|
|
public async Task<List<T>> QueryTreeByClauseAsync(
|
|
|
|
|
Expression<Func<T, object>> parentIdExpression, object primaryKeyValue, bool isContainOneself = true)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.ToChildListAsync(parentIdExpression, primaryKeyValue, isContainOneself);
|
|
|
|
|
}
|
|
|
|
|
public async Task<List<T>> QueryTreeByClauseAsync(
|
|
|
|
|
Expression<Func<T, bool>> expression,
|
|
|
|
|
Expression<Func<T, object>> expression1,
|
|
|
|
|
Expression<Func<T, IEnumerable<object>>> childListExpression, Expression<Func<T, object>> parentIdExpression, object rootValue
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.Where(expression)
|
|
|
|
|
.OrderBy(expression1, OrderByType.Asc)
|
|
|
|
|
.ToTreeAsync(childListExpression, parentIdExpression, rootValue);
|
|
|
|
|
}
|
|
|
|
|
public async Task<List<T>> QueryTreeByClauseAsync(
|
|
|
|
|
Expression<Func<T, bool>> expression,
|
|
|
|
|
Expression<Func<T, object>> expression1,
|
|
|
|
|
Expression<Func<T, IEnumerable<object>>> childListExpression, Expression<Func<T, object>> parentIdExpression, object rootValue, object[] childIds
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.Where(expression)
|
|
|
|
|
.OrderBy(expression1, OrderByType.Asc)
|
|
|
|
|
.ToTreeAsync(childListExpression, parentIdExpression, rootValue, childIds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据条件查询数据
|
|
|
|
@ -277,6 +475,19 @@ public abstract class BaseRepository<T> where T : class, new()
|
|
|
|
|
.WithNoLockOrNot(blUseNoLock)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
public async Task<List<TResult>> QueryListByClauseAsync<TResult>(
|
|
|
|
|
Expression<Func<T, bool>> expression,
|
|
|
|
|
bool isWhere, Expression<Func<T, bool>> whereIfExpression,
|
|
|
|
|
Expression<Func<T, TResult>> selectExpression
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.Where(expression)
|
|
|
|
|
.WhereIF(isWhere, whereIfExpression)
|
|
|
|
|
.Select(selectExpression)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据条件查询一定数量数据
|
|
|
|
@ -387,6 +598,47 @@ public abstract class BaseRepository<T> where T : class, new()
|
|
|
|
|
.WithNoLockOrNot(blUseNoLock)
|
|
|
|
|
.FirstAsync(predicate);
|
|
|
|
|
}
|
|
|
|
|
public async Task<List<TResult>> QueryByGroupByAsync<TResult>(
|
|
|
|
|
Expression<Func<T, object>> expression,
|
|
|
|
|
Expression<Func<T, TResult>> expression2
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.GroupBy(expression)
|
|
|
|
|
.Select(expression2)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
public async Task<List<long>> QueryByClauseAsync(Expression<Func<T, bool>> predicate, Expression<Func<T, long>> selectExpression, bool blUseNoLock = false)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.Where(predicate)
|
|
|
|
|
.Select(selectExpression)
|
|
|
|
|
.WithNoLockOrNot(blUseNoLock)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<int> UpdateColumnsAsync(
|
|
|
|
|
T updateObj,
|
|
|
|
|
Expression<Func<T, object>> columns
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Updateable(updateObj)
|
|
|
|
|
.UpdateColumns(columns)
|
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<List<T>> QueryListByClauseAsync(
|
|
|
|
|
Expression<Func<T, bool>> expression)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.Where(expression)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据条件查询数据
|
|
|
|
@ -423,6 +675,99 @@ public abstract class BaseRepository<T> where T : class, new()
|
|
|
|
|
.WithNoLockOrNot(blUseNoLock)
|
|
|
|
|
.FirstAsync(predicate);
|
|
|
|
|
}
|
|
|
|
|
public async Task<List<T>> QueryByOrderByClauseAsync
|
|
|
|
|
(
|
|
|
|
|
Expression<Func<T, bool>> expression,
|
|
|
|
|
Expression<Func<T, object>> expression1,
|
|
|
|
|
bool blUseNoLock = false)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.Where(expression)
|
|
|
|
|
.OrderBy(expression1, OrderByType.Asc)
|
|
|
|
|
.WithNoLockOrNot(blUseNoLock)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
public List<T> QueryByClauseToList(
|
|
|
|
|
Expression<Func<T, bool>> expression, Expression<Func<T, bool>> expression2,
|
|
|
|
|
Expression<Func<T, object>> expression1, bool blUseNoLock = false)
|
|
|
|
|
{
|
|
|
|
|
return DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.Where(expression)
|
|
|
|
|
.Where(expression2)
|
|
|
|
|
.OrderBy(expression1, OrderByType.Asc)
|
|
|
|
|
.WithNoLockOrNot(blUseNoLock)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
public List<T> QueryByClauseToList(Expression<Func<T, bool>> expression, Expression<Func<T, bool>> expression2, bool blUseNoLock = false)
|
|
|
|
|
{
|
|
|
|
|
return DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.Where(expression)
|
|
|
|
|
.Where(expression2)
|
|
|
|
|
.WithNoLockOrNot(blUseNoLock)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
public List<T> QueryByClauseToList(Expression<Func<T, bool>> expression, Expression<Func<T, object>> expression1, bool blUseNoLock = false)
|
|
|
|
|
{
|
|
|
|
|
return DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.Where(expression)
|
|
|
|
|
.OrderBy(expression1, OrderByType.Asc)
|
|
|
|
|
.WithNoLockOrNot(blUseNoLock)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
public List<T> QueryByClauseToList(Expression<Func<T, bool>> expression)
|
|
|
|
|
{
|
|
|
|
|
return DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.Where(expression)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
/// <typeparam name="T2"></typeparam>
|
|
|
|
|
/// <typeparam name="TResult"></typeparam>
|
|
|
|
|
/// <param name="joinExpression"></param>
|
|
|
|
|
/// <param name="whereExpression"></param>
|
|
|
|
|
/// <param name="orderExpression"></param>
|
|
|
|
|
/// <param name="selectExpression"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<List<TResult>> QueryByClauseAsync<T, T2, TResult>(
|
|
|
|
|
Expression<Func<T, T2, bool>> joinExpression,
|
|
|
|
|
Expression<Func<T, T2, bool>> whereExpression,
|
|
|
|
|
Expression<Func<T, T2, object>> orderExpression,
|
|
|
|
|
Expression<Func<T, T2, TResult>> selectExpression
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.LeftJoin<T2>(joinExpression)
|
|
|
|
|
.Where(whereExpression)
|
|
|
|
|
.OrderBy(orderExpression, OrderByType.Asc)
|
|
|
|
|
.Select(selectExpression)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
public async Task<List<TResult>> QueryByClauseAsync<T, T2, TResult>(
|
|
|
|
|
Expression<Func<T, T2, bool>> joinExpression,
|
|
|
|
|
Expression<Func<T, T2, bool>> whereExpression,
|
|
|
|
|
bool isWhere, Expression<Func<T, T2, bool>> whereifExpression,
|
|
|
|
|
Expression<Func<T, T2, object>> orderExpression,
|
|
|
|
|
Expression<Func<T, T2, TResult>> selectExpression
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.LeftJoin<T2>(joinExpression)
|
|
|
|
|
.Where(whereExpression)
|
|
|
|
|
.WhereIF(isWhere, whereifExpression)
|
|
|
|
|
.OrderBy(orderExpression, OrderByType.Asc)
|
|
|
|
|
.Select(selectExpression)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 写入实体数据
|
|
|
|
@ -435,6 +780,16 @@ public abstract class BaseRepository<T> where T : class, new()
|
|
|
|
|
.Insertable(entity)
|
|
|
|
|
.ExecuteReturnIdentity();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 写入或者更新实体数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="entity">实体数据</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public int InsertOrUpdate(T entity)
|
|
|
|
|
{
|
|
|
|
|
return DbBaseClient.Storageable(entity).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 写入实体数据
|
|
|
|
@ -447,7 +802,12 @@ public abstract class BaseRepository<T> where T : class, new()
|
|
|
|
|
.Insertable(entity)
|
|
|
|
|
.ExecuteReturnIdentityAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<T> InsertReturnEntityAsync(T entity)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Insertable(entity)
|
|
|
|
|
.ExecuteReturnEntityAsync();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 写入实体数据
|
|
|
|
|
/// </summary>
|
|
|
|
@ -554,6 +914,64 @@ public abstract class BaseRepository<T> where T : class, new()
|
|
|
|
|
return await DbBaseClient.Updateable(entity).ExecuteCommandHasChangeAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<bool> UpdateAsync(
|
|
|
|
|
Expression<Func<T, bool>> expression
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.ClearFilter()
|
|
|
|
|
.AnyAsync(expression);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Update(Expression<Func<T, bool>> columns,
|
|
|
|
|
Expression<Func<T, bool>> expression)
|
|
|
|
|
{
|
|
|
|
|
return DbBaseClient.Updateable<T>().SetColumns(columns).Where(expression).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<int> UpdateAsync(
|
|
|
|
|
Expression<Func<T, bool>> columns,
|
|
|
|
|
Expression<Func<T, bool>> expression
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Updateable<T>()
|
|
|
|
|
.SetColumns(columns)
|
|
|
|
|
.Where(expression)
|
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<int> UpdateAsync(
|
|
|
|
|
Expression<Func<T, object>> columns
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Updateable<T>()
|
|
|
|
|
.IgnoreColumns(columns)
|
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
public async Task<int> UpdateAsync(
|
|
|
|
|
T updateObj,
|
|
|
|
|
bool ignoreAllNullColumns
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Updateable(updateObj)
|
|
|
|
|
.IgnoreColumns(ignoreAllNullColumns)
|
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
public async Task<int> UpdateAsync(
|
|
|
|
|
T updateObj, bool ignoreAllNullColumns, Expression<Func<T, object>> columns
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient
|
|
|
|
|
.Updateable<T>(updateObj)
|
|
|
|
|
.IgnoreColumns(ignoreAllNullColumns)
|
|
|
|
|
.IgnoreColumns(columns)
|
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新实体数据
|
|
|
|
|
/// </summary>
|
|
|
|
@ -574,6 +992,7 @@ public abstract class BaseRepository<T> where T : class, new()
|
|
|
|
|
return await DbBaseClient.Updateable(entity).ExecuteCommandHasChangeAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据手写条件更新
|
|
|
|
|
/// </summary>
|
|
|
|
@ -718,7 +1137,23 @@ public abstract class BaseRepository<T> where T : class, new()
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient.Deleteable<T>(entity).ExecuteCommandHasChangeAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 新增方法
|
|
|
|
|
/// 该方法用于:根据角色Id删除用户角色
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="predicate"></param>
|
|
|
|
|
/// <param name="selectExpression"></param>
|
|
|
|
|
/// <param name="action"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task DeleteUserRoleByRoleId(
|
|
|
|
|
Expression<Func<T, bool>> predicate,
|
|
|
|
|
Expression<Func<T, long>> selectExpression, Action<long> action)
|
|
|
|
|
{
|
|
|
|
|
await DbBaseClient.Queryable<T>()
|
|
|
|
|
.Where(predicate)
|
|
|
|
|
.Select(selectExpression)
|
|
|
|
|
.ForEachAsync(action);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除数据
|
|
|
|
|
/// </summary>
|
|
|
|
@ -1043,99 +1478,100 @@ public abstract class BaseRepository<T> where T : class, new()
|
|
|
|
|
{
|
|
|
|
|
return await DbBaseClient.Queryable<T>().Where(predicate).WithNoLockOrNot(blUseNoLock).SumAsync(field);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据条件查询表单数据(分页)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="page"> 页数</param>
|
|
|
|
|
/// <param name="pageSize">每页几条数据</param>
|
|
|
|
|
/// <param name="blUseNoLock">是否使用WITH(NOLOCK)</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public IPage<T> QueryIPageByCause(QueryPageModel page, Expression<Func<T, bool>> predicate)
|
|
|
|
|
{
|
|
|
|
|
if (null == predicate)
|
|
|
|
|
{
|
|
|
|
|
return this.QueryIPage(page);
|
|
|
|
|
}
|
|
|
|
|
int totalCount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<T> pageList = DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.Where(predicate)
|
|
|
|
|
.WithNoLockOrNot(false)
|
|
|
|
|
.ToPageList(page.Page, page.PageSize, ref totalCount);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new IPage<T>(totalCount, page, pageList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据条件查询表单数据(分页) 异步
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="page"></param>
|
|
|
|
|
/// <param name="predicate"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<IPage<T>> QueryIPageByCauseAsync(QueryPageModel page, Expression<Func<T, bool>> predicate)
|
|
|
|
|
public async Task<List<T>> QueryPageByIncludeAsync<TReturn1>(Expression<Func<T, TReturn1>> include1,
|
|
|
|
|
Expression<Func<T, bool>> whereExpression, bool isWhere, Expression<Func<T, bool>> expression,
|
|
|
|
|
bool isWhere1, Expression<Func<T, bool>> expression1,
|
|
|
|
|
Expression<Func<T, object>> orderExpression,
|
|
|
|
|
//TODO::
|
|
|
|
|
int pageIndex = 1, int pageSize = 20, RefAsync<int> totalNumber = null, bool blUseNoLock = false)
|
|
|
|
|
{
|
|
|
|
|
if (null == predicate)
|
|
|
|
|
{
|
|
|
|
|
return await this.QueryIPageAsync(page);
|
|
|
|
|
}
|
|
|
|
|
RefAsync<int> totalCount = 0;
|
|
|
|
|
|
|
|
|
|
var page = await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.Includes(include1)
|
|
|
|
|
.Where(whereExpression)
|
|
|
|
|
.WhereIF(isWhere, expression)
|
|
|
|
|
.WhereIF(isWhere1, expression1)
|
|
|
|
|
.OrderBy(orderExpression, OrderByType.Asc)
|
|
|
|
|
.WithNoLockOrNot(blUseNoLock)
|
|
|
|
|
.ToPageListAsync(pageIndex, pageSize, totalNumber);
|
|
|
|
|
return page;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<T> pageList = await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.Where(predicate)
|
|
|
|
|
.WithNoLockOrNot(false)
|
|
|
|
|
.ToPageListAsync(page.Page, page.PageSize, totalCount);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new IPage<T>(totalCount, page, pageList);
|
|
|
|
|
public async Task<List<T>> QueryPageAsync(
|
|
|
|
|
bool isWhere1, Expression<Func<T, bool>> expression1,
|
|
|
|
|
bool isWhere2, Expression<Func<T, bool>> expression2,
|
|
|
|
|
Expression<Func<T, object>> orderBy,
|
|
|
|
|
int pageNumber, int pageSize, RefAsync<int> totalNumber,
|
|
|
|
|
bool blUseNoLock = false)
|
|
|
|
|
{
|
|
|
|
|
var page = await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.OrderBy(orderBy, OrderByType.Asc)
|
|
|
|
|
.WhereIF(isWhere1, expression1)
|
|
|
|
|
.WhereIF(isWhere2, expression2)
|
|
|
|
|
.WithNoLockOrNot(blUseNoLock)
|
|
|
|
|
.ToPageListAsync(pageNumber, pageSize, totalNumber);
|
|
|
|
|
return page;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询表单所有数据(分页)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="page"> 页数</param>
|
|
|
|
|
/// <param name="pageSize">每页几条数据</param>
|
|
|
|
|
/// <param name="blUseNoLock">是否使用WITH(NOLOCK)</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public IPage<T> QueryIPage(QueryPageModel page)
|
|
|
|
|
public async Task<List<T>> QueryPageAsync(
|
|
|
|
|
bool isWhere1, Expression<Func<T, bool>> expression1,
|
|
|
|
|
bool isWhere2, Expression<Func<T, bool>> expression2,
|
|
|
|
|
int pageNumber, int pageSize, RefAsync<int> totalNumber,
|
|
|
|
|
bool blUseNoLock = false)
|
|
|
|
|
{
|
|
|
|
|
int totalCount = 0;
|
|
|
|
|
//page.Page = page.Page == 0 ? 1 : page.Page;//默认第一页 10条数据
|
|
|
|
|
//page.PageSize = page.PageSize == 0 ? 10 : page.PageSize;
|
|
|
|
|
var page = await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.WhereIF(isWhere1, expression1)
|
|
|
|
|
.WhereIF(isWhere2, expression2)
|
|
|
|
|
.WithNoLockOrNot(blUseNoLock)
|
|
|
|
|
.ToPageListAsync(pageNumber, pageSize, totalNumber);
|
|
|
|
|
return page;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<T> pageList = DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.WithNoLockOrNot(false)
|
|
|
|
|
.ToPageList(page.Page, page.PageSize, ref totalCount);
|
|
|
|
|
|
|
|
|
|
return new IPage<T>(totalCount, page, pageList);
|
|
|
|
|
public async Task<List<T>> QueryPageAsync(
|
|
|
|
|
bool isWhere1, Expression<Func<T, bool>> expression1,
|
|
|
|
|
bool isWhere2, Expression<Func<T, bool>> expression2,
|
|
|
|
|
bool isWhere3, Expression<Func<T, bool>> expression3,
|
|
|
|
|
Expression<Func<T, object>> orderBy,
|
|
|
|
|
int pageNumber, int pageSize, RefAsync<int> totalNumber,
|
|
|
|
|
bool blUseNoLock = false)
|
|
|
|
|
{
|
|
|
|
|
var page = await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.OrderBy(orderBy, OrderByType.Asc)
|
|
|
|
|
.WhereIF(isWhere1, expression1)
|
|
|
|
|
.WhereIF(isWhere2, expression2)
|
|
|
|
|
.WhereIF(isWhere3, expression3)
|
|
|
|
|
.WithNoLockOrNot(blUseNoLock)
|
|
|
|
|
.ToPageListAsync(pageNumber, pageSize, totalNumber);
|
|
|
|
|
return page;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询表单所有数据(分页) 异步
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="page"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<IPage<T>> QueryIPageAsync(QueryPageModel page)
|
|
|
|
|
public async Task<List<T>> QueryPageAsync(
|
|
|
|
|
bool isWhere1, Expression<Func<T, bool>> expression1,
|
|
|
|
|
bool isWhere2, Expression<Func<T, bool>> expression2,
|
|
|
|
|
bool isWhere3, Expression<Func<T, bool>> expression3,
|
|
|
|
|
int pageNumber, int pageSize, RefAsync<int> totalNumber,
|
|
|
|
|
PageConfigReq input, bool blUseNoLock = false)
|
|
|
|
|
{
|
|
|
|
|
RefAsync<int> totalCount = 0;
|
|
|
|
|
|
|
|
|
|
List<T> pageList = await DbBaseClient
|
|
|
|
|
var page = await DbBaseClient
|
|
|
|
|
.Queryable<T>()
|
|
|
|
|
.WithNoLockOrNot(false)
|
|
|
|
|
.ToPageListAsync(page.Page, page.PageSize, totalCount);
|
|
|
|
|
|
|
|
|
|
return new IPage<T>(totalCount, page, pageList);
|
|
|
|
|
.WhereIF(isWhere1, expression1)
|
|
|
|
|
.WhereIF(isWhere2, expression2)
|
|
|
|
|
.WhereIF(isWhere3, expression3)
|
|
|
|
|
.OrderBuilder(input)
|
|
|
|
|
.WithNoLockOrNot(blUseNoLock)
|
|
|
|
|
.ToPageListAsync(pageNumber, pageSize, totalNumber);
|
|
|
|
|
return page;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询-2表查询
|
|
|
|
|
/// </summary>
|
|
|
|
@ -1337,4 +1773,7 @@ public abstract class BaseRepository<T> where T : class, new()
|
|
|
|
|
var list = await DbBaseClient.SqlQueryable<T>(sql).ToListAsync();
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|