diff --git a/Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/Storageable.cs b/Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/Storageable.cs index f08b800dc..025a90fd9 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/Storageable.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/Storageable.cs @@ -17,6 +17,7 @@ namespace SqlSugar List, bool>, string>> whereFuncs = new List, bool>, string>>(); Expression> whereExpression; Func formatTime; + DbLockType? lockType; private string asname { get; set; } public Storageable(List datas, SqlSugarProvider context) { @@ -63,6 +64,11 @@ namespace SqlSugar return this; } + public IStorageable TranLock(DbLockType dbLockType = DbLockType.Wait) + { + this.lockType = dbLockType; + return this; + } public IStorageable SplitOther(Func, bool> conditions, string message = null) { whereFuncs.Add(new KeyValuePair, 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().AS(asname).WhereClassByPrimaryKey(item.Select(it => it.Item).ToList()).ToList(); + var addItems=this.Context.Queryable().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().AS(asname).WhereClassByPrimaryKey(item.Select(it => it.Item).ToList()).ToListAsync(); + var addItems =await this.Context.Queryable().AS(asname).TranLock(this.lockType).WhereClassByPrimaryKey(item.Select(it => it.Item).ToList()).ToListAsync(); dbDataList.AddRange(addItems); }); } diff --git a/Src/Asp.Net/SqlSugar/Interface/IStorageable.cs b/Src/Asp.Net/SqlSugar/Interface/IStorageable.cs index b2df5066b..f35e0ba47 100644 --- a/Src/Asp.Net/SqlSugar/Interface/IStorageable.cs +++ b/Src/Asp.Net/SqlSugar/Interface/IStorageable.cs @@ -17,6 +17,7 @@ namespace SqlSugar IStorageable Saveable(string inserMessage = null, string updateMessage = null); IStorageable SplitError(Func, bool> conditions, string message = null); IStorageable SplitIgnore(Func, bool> conditions, string message = null); + IStorageable TranLock(DbLockType LockType = DbLockType.Wait); IStorageable SplitDelete(Func, bool> conditions, string message = null); IStorageable SplitOther(Func, bool> conditions, string message = null); StorageableResult ToStorage();