Add db.Storageable(data).TranLock

This commit is contained in:
sunkaixuan 2022-08-23 20:11:24 +08:00
parent 57f36a37a8
commit c2d825e005
2 changed files with 9 additions and 2 deletions

View File

@ -17,6 +17,7 @@ namespace SqlSugar
List<KeyValuePair<StorageType, Func<StorageableInfo<T>, bool>, string>> whereFuncs = new List<KeyValuePair<StorageType, Func<StorageableInfo<T>, bool>, string>>();
Expression<Func<T, object>> whereExpression;
Func<DateTime, string> formatTime;
DbLockType? lockType;
private string asname { get; set; }
public Storageable(List<T> datas, SqlSugarProvider context)
{
@ -63,6 +64,11 @@ namespace SqlSugar
return this;
}
public IStorageable<T> TranLock(DbLockType dbLockType = DbLockType.Wait)
{
this.lockType = dbLockType;
return this;
}
public IStorageable<T> SplitOther(Func<StorageableInfo<T>, bool> conditions, string message = null)
{
whereFuncs.Add(new KeyValuePair<StorageType, Func<StorageableInfo<T>, bool>, string>(StorageType.Other, conditions, message));
@ -114,7 +120,7 @@ namespace SqlSugar
if (whereExpression == null && pkInfos.Any())
{
this.Context.Utilities.PageEach(allDatas, 300, item => {
var addItems=this.Context.Queryable<T>().AS(asname).WhereClassByPrimaryKey(item.Select(it => it.Item).ToList()).ToList();
var addItems=this.Context.Queryable<T>().TranLock(this.lockType).AS(asname).WhereClassByPrimaryKey(item.Select(it => it.Item).ToList()).ToList();
dbDataList.AddRange(addItems);
});
}
@ -196,7 +202,7 @@ namespace SqlSugar
if (whereExpression == null && pkInfos.Any())
{
await this.Context.Utilities.PageEachAsync(allDatas, 300,async item => {
var addItems =await this.Context.Queryable<T>().AS(asname).WhereClassByPrimaryKey(item.Select(it => it.Item).ToList()).ToListAsync();
var addItems =await this.Context.Queryable<T>().AS(asname).TranLock(this.lockType).WhereClassByPrimaryKey(item.Select(it => it.Item).ToList()).ToListAsync();
dbDataList.AddRange(addItems);
});
}

View File

@ -17,6 +17,7 @@ namespace SqlSugar
IStorageable<T> Saveable(string inserMessage = null, string updateMessage = null);
IStorageable<T> SplitError(Func<StorageableInfo<T>, bool> conditions, string message = null);
IStorageable<T> SplitIgnore(Func<StorageableInfo<T>, bool> conditions, string message = null);
IStorageable<T> TranLock(DbLockType LockType = DbLockType.Wait);
IStorageable<T> SplitDelete(Func<StorageableInfo<T>, bool> conditions, string message = null);
IStorageable<T> SplitOther(Func<StorageableInfo<T>, bool> conditions, string message = null);
StorageableResult<T> ToStorage();