Update merge

This commit is contained in:
sunkaixuan
2025-10-25 09:52:55 +08:00
parent 6752281de2
commit 056109f140
3 changed files with 25 additions and 3 deletions

View File

@@ -2,7 +2,7 @@
<package >
<metadata>
<id>SqlSugar.Nhgdb</id>
<version>5.1.4.159</version>
<version>5.1.4.205</version>
<authors>sunkaixuan</authors>
<owners>Landa</owners>
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl>

View File

@@ -7,6 +7,7 @@ using System.Linq;
using System.Threading;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Linq.Expressions;
namespace SqlSugar
{
public partial class FastestProvider<T>:IFastest<T> where T:class,new()
@@ -244,6 +245,25 @@ namespace SqlSugar
return BulkMergeAsync(datas, whereColumns, updateColumns).GetAwaiter().GetResult();
}
public async Task<int> BulkMergeAsync(List<T> datas, Expression<Func<T, object>> whereColumnsExp, Expression<Func<T, object>> updateColumnsExp)
{
// 步骤:
// 1. 通过表达式获取 whereColumns 和 updateColumns 的列名数组
// 2. 调用已有的 BulkMergeAsync(List<T>, string[], string[]) 方法
// 1. 获取 whereColumns
var whereColumns =ExpressionTool.GetNewArrayMembers((whereColumnsExp as LambdaExpression).Body as NewArrayExpression);
// 2. 获取 updateColumns
var updateColumns = ExpressionTool.GetNewArrayMembers((updateColumnsExp as LambdaExpression).Body as NewArrayExpression);
// 3. 调用 BulkMergeAsync
return await BulkMergeAsync(datas, whereColumns?.ToArray(), updateColumns?.ToArray());
}
public int BulkMerge(List<T> datas, Expression<Func<T, object>> whereColumnsExp, Expression<Func<T, object>> updateColumnsExp)
{
return BulkMergeAsync(datas, whereColumnsExp, updateColumnsExp).GetAwaiter().GetResult();
}
private async Task<int> _BulkMerge(List<T> datas, string[] updateColumns, string[] whereColumns)
{
try

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
@@ -45,6 +46,7 @@ namespace SqlSugar
int BulkMerge(List<T> datas, string[] whereColumns);
Task<int> BulkMergeAsync(List<T> datas, string[] whereColumns, string[] updateColumns);
int BulkMerge(List<T> datas, string[] whereColumns, string[] updateColumns);
Task<int> BulkMergeAsync(List<T> datas, Expression<Func<T, object>> whereColumnsExp, Expression<Func<T, object>> updateColumnsExp);
int BulkMerge(List<T> datas, Expression<Func<T, object>> whereColumnsExp, Expression<Func<T, object>> updateColumnsExp);
}
}