From 54d7743a36fdd16df71a8f87aae2864e728669c2 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Mon, 24 Mar 2025 15:47:37 +0800 Subject: [PATCH] Update WhereColumns --- .../SqlSugar/Realization/Dm/SqlBuilder/DmUpdateBuilder.cs | 8 ++++++++ .../Realization/Oracle/SqlBuilder/OracleUpdateBuilder.cs | 8 ++++++++ .../Realization/Sqlite/SqlBuilder/SqliteUpdateBuilder.cs | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/Src/Asp.NetCore2/SqlSugar/Realization/Dm/SqlBuilder/DmUpdateBuilder.cs b/Src/Asp.NetCore2/SqlSugar/Realization/Dm/SqlBuilder/DmUpdateBuilder.cs index 7a9ffe9b6..254a60115 100644 --- a/Src/Asp.NetCore2/SqlSugar/Realization/Dm/SqlBuilder/DmUpdateBuilder.cs +++ b/Src/Asp.NetCore2/SqlSugar/Realization/Dm/SqlBuilder/DmUpdateBuilder.cs @@ -28,6 +28,14 @@ namespace SqlSugar var updateTable = string.Format("UPDATE {0} SET", base.GetTableNameStringNoWith); var setValues = string.Join(",", t.Where(s => !s.IsPrimarykey).Where(s => OldPrimaryKeys == null || !OldPrimaryKeys.Contains(s.DbColumnName)).Select(m => GetOracleUpdateColums(i, m)).ToArray()); var pkList = t.Where(s => s.IsPrimarykey).ToList(); + if (this.IsWhereColumns && this.PrimaryKeys?.Any() == true) + { + var whereColumns = pkList.Where(it => this.PrimaryKeys?.Any(p => p.EqualCase(it.PropertyName) || p.EqualCase(it.DbColumnName)) == true).ToList(); + if (whereColumns.Any()) + { + pkList = whereColumns; + } + } List whereList = new List(); foreach (var item in pkList) { diff --git a/Src/Asp.NetCore2/SqlSugar/Realization/Oracle/SqlBuilder/OracleUpdateBuilder.cs b/Src/Asp.NetCore2/SqlSugar/Realization/Oracle/SqlBuilder/OracleUpdateBuilder.cs index adc092434..daade0f47 100644 --- a/Src/Asp.NetCore2/SqlSugar/Realization/Oracle/SqlBuilder/OracleUpdateBuilder.cs +++ b/Src/Asp.NetCore2/SqlSugar/Realization/Oracle/SqlBuilder/OracleUpdateBuilder.cs @@ -22,6 +22,14 @@ namespace SqlSugar var updateTable = string.Format("UPDATE {0} SET", base.GetTableNameStringNoWith); var setValues = string.Join(",", t.Where(s => !s.IsPrimarykey).Where(s => OldPrimaryKeys == null || !OldPrimaryKeys.Contains(s.DbColumnName)).Select(m => GetOracleUpdateColums(m)).ToArray()); var pkList = t.Where(s => s.IsPrimarykey).ToList(); + if (this.IsWhereColumns && this.PrimaryKeys?.Any() == true) + { + var whereColumns = pkList.Where(it => this.PrimaryKeys?.Any(p => p.EqualCase(it.PropertyName) || p.EqualCase(it.DbColumnName)) == true).ToList(); + if (whereColumns.Any()) + { + pkList = whereColumns; + } + } List whereList = new List(); foreach (var item in pkList) { diff --git a/Src/Asp.NetCore2/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteUpdateBuilder.cs b/Src/Asp.NetCore2/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteUpdateBuilder.cs index a0302cb54..5a2524c97 100644 --- a/Src/Asp.NetCore2/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteUpdateBuilder.cs +++ b/Src/Asp.NetCore2/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteUpdateBuilder.cs @@ -17,6 +17,14 @@ namespace SqlSugar var updateTable = string.Format("UPDATE {0} SET", base.GetTableNameStringNoWith); var setValues = string.Join(",", t.Where(s => !s.IsPrimarykey).Where(s=> OldPrimaryKeys==null||!OldPrimaryKeys.Contains(s.DbColumnName)).Select(m => GetOracleUpdateColums(i,m,false)).ToArray()); var pkList = t.Where(s => s.IsPrimarykey).ToList(); + if (this.IsWhereColumns&& this.PrimaryKeys?.Any()==true) + { + var whereColumns = pkList.Where(it => this.PrimaryKeys?.Any(p => p.EqualCase(it.PropertyName) || p.EqualCase(it.DbColumnName))==true).ToList(); + if (whereColumns.Any()) + { + pkList = whereColumns; + } + } List whereList = new List(); foreach (var item in pkList) {