From df2f45b7aa1983a3c99015a8c8073f97cf667688 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sat, 23 Sep 2023 13:38:12 +0800 Subject: [PATCH] Synchronization code --- .../Abstract/DbFirstProvider/DbFirstProvider.cs | 4 ++++ .../Abstract/SaveableProvider/Storageable.cs | 13 +++++++++++++ .../Abstract/SaveableProvider/StorageablePage.cs | 10 ++++++---- Src/Asp.Net/SqlSugar/Interface/IStorageable.cs | 1 + 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Src/Asp.Net/SqlSugar/Abstract/DbFirstProvider/DbFirstProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/DbFirstProvider/DbFirstProvider.cs index 71de5b63c..9dca52059 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/DbFirstProvider/DbFirstProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/DbFirstProvider/DbFirstProvider.cs @@ -465,6 +465,10 @@ namespace SqlSugar { return "bool"; } + if (result.EqualCase("char")) + { + return "string"; + } return result; } private string GetPropertyTypeConvert(DbColumnInfo item) diff --git a/Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/Storageable.cs b/Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/Storageable.cs index ce0f5485e..4478304de 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/Storageable.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/Storageable.cs @@ -84,6 +84,18 @@ namespace SqlSugar this.lockType = dbLockType; return this; } + public IStorageable TranLock(DbLockType? LockType) + { + if (LockType!=null) + { + this.lockType = LockType; + return this; + } + else + { + return this; + } + } public IStorageable SplitOther(Func, bool> conditions, string message = null) { whereFuncs.Add(new KeyValuePair, bool>, string>(StorageType.Other, conditions, message)); @@ -102,6 +114,7 @@ namespace SqlSugar page.ActionCallBack = ActionCallBack; page.TableName = this.asname; page.whereExpression = this.whereExpression; + page.lockType = this.lockType; return page; } public StorageableSplitProvider SplitTable() diff --git a/Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/StorageablePage.cs b/Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/StorageablePage.cs index d667af460..f957e4455 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/StorageablePage.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/StorageablePage.cs @@ -9,6 +9,8 @@ namespace SqlSugar { public class StorageablePage where T : class,new() { + internal DbLockType? lockType { get; set; } + public SqlSugarProvider Context { get; set; } public List Data { get; set; } public int PageSize { get; internal set; } @@ -33,7 +35,7 @@ namespace SqlSugar } this.Context.Utilities.PageEach(Data, PageSize, pageItem => { - result += this.Context.Storageable(pageItem).As(TableName).WhereColumns(whereExpression).ExecuteCommand(); + result += this.Context.Storageable(pageItem).As(TableName).TranLock(lockType).WhereColumns(whereExpression).ExecuteCommand(); if (ActionCallBack != null) { ActionCallBack(result); @@ -71,7 +73,7 @@ namespace SqlSugar } await this.Context.Utilities.PageEachAsync(Data, PageSize, async pageItem => { - result += await this.Context.Storageable(pageItem).As(TableName).WhereColumns(whereExpression).ExecuteCommandAsync(); + result += await this.Context.Storageable(pageItem).As(TableName).TranLock(lockType).WhereColumns(whereExpression).ExecuteCommandAsync(); if (ActionCallBack != null) { ActionCallBack(result); @@ -106,7 +108,7 @@ namespace SqlSugar this.Context.Utilities.PageEach(Data, PageSize, pageItem => { - result += this.Context.Storageable(pageItem).As(TableName).WhereColumns(whereExpression).ExecuteSqlBulkCopy(); + result += this.Context.Storageable(pageItem).As(TableName).TranLock(lockType).WhereColumns(whereExpression).ExecuteSqlBulkCopy(); if (ActionCallBack != null) { ActionCallBack(result); @@ -132,7 +134,7 @@ namespace SqlSugar { await this.Context.Utilities.PageEachAsync(Data, PageSize, async pageItem => { - result += await this.Context.Storageable(pageItem).As(TableName).WhereColumns(whereExpression).ExecuteSqlBulkCopyAsync(); + result += await this.Context.Storageable(pageItem).As(TableName).TranLock(lockType).WhereColumns(whereExpression).ExecuteSqlBulkCopyAsync(); if (ActionCallBack != null) { ActionCallBack(result); diff --git a/Src/Asp.Net/SqlSugar/Interface/IStorageable.cs b/Src/Asp.Net/SqlSugar/Interface/IStorageable.cs index 6fa69b9f7..e7c938f17 100644 --- a/Src/Asp.Net/SqlSugar/Interface/IStorageable.cs +++ b/Src/Asp.Net/SqlSugar/Interface/IStorageable.cs @@ -20,6 +20,7 @@ namespace SqlSugar IStorageable SplitIgnore(Func, bool> conditions, string message = null); IStorageable DisableFilters(); IStorageable TranLock(DbLockType LockType = DbLockType.Wait); + IStorageable TranLock(DbLockType? LockType); IStorageable SplitDelete(Func, bool> conditions, string message = null); IStorageable SplitOther(Func, bool> conditions, string message = null); StorageableResult ToStorage();