From 4ac1e1b08fa04369e6e9ca6dea71f219bd8eb09c Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Wed, 26 Jul 2023 17:20:07 +0800 Subject: [PATCH] Synchronization code --- .../SqlSugar/Entities/ConnMoreSettings.cs | 3 ++- .../ExpressionsToSql/Subquery/Items/SubInnerJoin.cs | 6 +++++- .../ExpressionsToSql/Subquery/Items/SubLeftJoin.cs | 6 +++++- .../SqlSugar/ExpressionsToSql/Subquery/SubResolve.cs | 11 +++++++++++ Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs | 3 ++- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Src/Asp.NetCore2/SqlSugar/Entities/ConnMoreSettings.cs b/Src/Asp.NetCore2/SqlSugar/Entities/ConnMoreSettings.cs index 9a8fa3495..31ab8ca7d 100644 --- a/Src/Asp.NetCore2/SqlSugar/Entities/ConnMoreSettings.cs +++ b/Src/Asp.NetCore2/SqlSugar/Entities/ConnMoreSettings.cs @@ -9,7 +9,8 @@ namespace SqlSugar { public bool IsAutoRemoveDataCache { get; set; } public bool IsWithNoLockQuery { get; set; } - + public bool IsWithNoLockSubquery { get; set; } + public bool DisableNvarchar { get; set; } public bool DisableMillisecond { get; set; } public bool PgSqlIsAutoToLower { get; set; } = true; diff --git a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Subquery/Items/SubInnerJoin.cs b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Subquery/Items/SubInnerJoin.cs index 06263ac04..18dbef0e5 100644 --- a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Subquery/Items/SubInnerJoin.cs +++ b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Subquery/Items/SubInnerJoin.cs @@ -30,7 +30,7 @@ namespace SqlSugar { get { - return 301; + return 302; } } @@ -55,6 +55,10 @@ namespace SqlSugar this.Context.GetTranslationColumnName(parameter.Name), tableName, null); + if (this.Context?.SugarContext?.Context?.CurrentConnectionConfig?.DbType==DbType.SqlServer&&this.Context?.SugarContext?.Context?.CurrentConnectionConfig?.MoreSettings?.IsWithNoLockSubquery==true) + { + joinString = $"{joinString} {SqlWith.NoLock} "; + } var result = joinString+ "ON " + SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple); //var selfParameterName = Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot; this.Context.JoinIndex++; diff --git a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Subquery/Items/SubLeftJoin.cs b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Subquery/Items/SubLeftJoin.cs index 058846b9b..cdcbd9931 100644 --- a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Subquery/Items/SubLeftJoin.cs +++ b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Subquery/Items/SubLeftJoin.cs @@ -30,7 +30,7 @@ namespace SqlSugar { get { - return 301; + return 302; } } @@ -55,6 +55,10 @@ namespace SqlSugar this.Context.GetTranslationColumnName(parameter.Name), tableName, null); + if (this.Context?.SugarContext?.Context?.CurrentConnectionConfig?.DbType == DbType.SqlServer && this.Context?.SugarContext?.Context?.CurrentConnectionConfig?.MoreSettings?.IsWithNoLockSubquery == true) + { + joinString = $"{joinString} {SqlWith.NoLock} "; + } var result = joinString+ "ON " + SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple); //var selfParameterName = Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot; this.Context.JoinIndex++; diff --git a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Subquery/SubResolve.cs b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Subquery/SubResolve.cs index 8842f9a6c..26f40e44a 100644 --- a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Subquery/SubResolve.cs +++ b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Subquery/SubResolve.cs @@ -243,6 +243,17 @@ namespace SqlSugar isubList.Add(new SubRightBracket()); isubList.Add(new SubSelectDefault()); } + var db = this.context?.SugarContext?.Context; + if (db != null&& db?.CurrentConnectionConfig?.DbType == DbType.SqlServer) + { + if (db.CurrentConnectionConfig?.MoreSettings?.IsWithNoLockSubquery == true) + { + if (!isubList.Any(it => it is SubWithNolock)) + { + isubList.Add(new SubWithNolock() { Context = this.context }); + } + } + } isubList = isubList.OrderBy(it => it.Sort).ToList(); var isHasWhere = isubList.Where(it => it is SubWhere).Any(); var isJoin = isubList.Any(it => it is SubInnerJoin || it is SubLeftJoin); diff --git a/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs b/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs index f2c924c7f..ffc0ad0cd 100644 --- a/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs +++ b/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs @@ -363,7 +363,8 @@ namespace SqlSugar IsAutoDeleteQueryFilter=it.MoreSettings.IsAutoDeleteQueryFilter, IsAutoUpdateQueryFilter = it.MoreSettings.IsAutoUpdateQueryFilter, EnableModelFuncMappingColumn=it.MoreSettings.EnableModelFuncMappingColumn, - EnableOracleIdentity = it.MoreSettings.EnableOracleIdentity + EnableOracleIdentity = it.MoreSettings.EnableOracleIdentity, + IsWithNoLockSubquery=it.MoreSettings.IsWithNoLockSubquery }, SqlMiddle = it.SqlMiddle == null ? null : new SqlMiddle