mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 16:03:25 +08:00
【优化】仓储单个数据查询增加悲观锁等待模式。
【优化】通过优惠券编码领取优惠券增加事务处理。
This commit is contained in:
@@ -364,13 +364,12 @@ namespace CoreCms.Net.Repository
|
||||
/// <param name="blUseNoLock">是否使用WITH(NoLock)</param>
|
||||
/// <param name="isDataCache">是否启用缓存</param>
|
||||
/// <param name="cacheTimes">缓存时长(分钟)</param>
|
||||
/// <param name="blUseTranLock">是否使用锁</param>
|
||||
/// <param name="dbLockType">数据锁类型</param>
|
||||
/// <returns></returns>
|
||||
public async Task<T> QueryByClauseAsync(Expression<Func<T, bool>> predicate, bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue)
|
||||
public async Task<T> QueryByClauseAsync(Expression<Func<T, bool>> predicate, bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue, bool blUseTranLock = false, DbLockType dbLockType = DbLockType.Wait)
|
||||
{
|
||||
return await DbBaseClient.Queryable<T>()
|
||||
.WithNoLockOrNot(blUseNoLock)
|
||||
.WithCacheIF(isDataCache, cacheTimes)
|
||||
.FirstAsync(predicate);
|
||||
return await DbBaseClient.Queryable<T>().WithNoLockOrNot(blUseNoLock).WithUseTranLockOrNot(blUseTranLock, dbLockType).WithCacheIF(isDataCache, cacheTimes).FirstAsync(predicate);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -397,27 +396,14 @@ namespace CoreCms.Net.Repository
|
||||
/// <param name="blUseNoLock">是否使用WITH(NoLock)</param>
|
||||
/// <param name="isDataCache">是否启用缓存</param>
|
||||
/// <param name="cacheTimes">缓存时长(分钟)</param>
|
||||
/// <param name="blUseTranLock">是否使用锁</param>
|
||||
/// <param name="dbLockType">数据锁类型</param>
|
||||
/// <returns></returns>
|
||||
public async Task<T> QueryByClauseAsync(Expression<Func<T, bool>> predicate, Expression<Func<T, object>> orderByPredicate, OrderByType orderByType, bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue)
|
||||
public async Task<T> QueryByClauseAsync(Expression<Func<T, bool>> predicate, Expression<Func<T, object>> orderByPredicate, OrderByType orderByType, bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue, bool blUseTranLock = false, DbLockType dbLockType = DbLockType.Wait)
|
||||
{
|
||||
return await DbBaseClient.Queryable<T>().OrderBy(orderByPredicate, orderByType).WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).FirstAsync(predicate);
|
||||
return await DbBaseClient.Queryable<T>().OrderBy(orderByPredicate, orderByType).WithNoLockOrNot(blUseNoLock).WithUseTranLockOrNot(blUseTranLock, dbLockType).WithCacheIF(isDataCache, cacheTimes).FirstAsync(predicate);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据条件查询数据(悲观锁等待模式)
|
||||
/// </summary>
|
||||
/// <param name="predicate">条件表达式树</param>
|
||||
/// <param name="orderByPredicate">排序字段</param>
|
||||
/// <param name="orderByType">排序顺序</param>
|
||||
/// <param name="blUseTranLock">是否使用TranLock</param>
|
||||
/// <param name="isDataCache">是否启用缓存</param>
|
||||
/// <param name="cacheTimes">缓存时长(分钟)</param>
|
||||
/// <returns></returns>
|
||||
public async Task<T> QueryByClauseWithTranLockAsync(Expression<Func<T, bool>> predicate, Expression<Func<T, object>> orderByPredicate, OrderByType orderByType, bool blUseTranLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue)
|
||||
{
|
||||
return await DbBaseClient.Queryable<T>().TranLock(DbLockType.Wait).OrderBy(orderByPredicate, orderByType).WithCacheIF(isDataCache, cacheTimes).FirstAsync(predicate);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 新增数据
|
||||
|
||||
@@ -14,6 +14,23 @@ namespace CoreCms.Net.Repository
|
||||
return query;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用锁
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="lock"></param>
|
||||
/// <param name="dbLockType"></param>
|
||||
/// <returns></returns>
|
||||
internal static ISugarQueryable<T> WithUseTranLockOrNot<T>(this ISugarQueryable<T> query, bool @lock = false, DbLockType dbLockType = DbLockType.Wait)
|
||||
{
|
||||
if (@lock)
|
||||
{
|
||||
query = query.TranLock(dbLockType);
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user