From 0c2bb4569b754d8741f72202f9b92bbee5a755b2 Mon Sep 17 00:00:00 2001 From: hantzl Date: Tue, 30 Sep 2025 16:29:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=20Fastest().BulkCopyAsync?= =?UTF-8?q?=20=20=E4=B8=8D=E4=BC=9A=E5=AF=B9=E9=89=B4=E5=88=AB=E5=99=A8?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E8=87=AA=E5=8A=A8=E8=B5=8B=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Abstract/FastestProvider/Private.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/FastestProvider/Private.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/FastestProvider/Private.cs index a0e4f705f..6858e62e5 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/FastestProvider/Private.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/FastestProvider/Private.cs @@ -4,6 +4,7 @@ using System.Data; using System.Linq; using System.Linq.Expressions; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; namespace SqlSugar @@ -105,6 +106,17 @@ namespace SqlSugar var tempColumns = tempDataTable.Columns.Cast().Select(it=>it.ColumnName); columns = columns.Where(it => tempColumns.Any(s => s.EqualCase(it.DbColumnName))).ToList(); } + var (isDiscrimator, discrimatorDict) = GetDiscrimator(); + + if (isDiscrimator && discrimatorDict?.Count > 0) + { + foreach (var dict in discrimatorDict) + { + if (!dt.Columns.Contains(dict.Key)) + dt.Columns.Add(dict.Key); + } + } + var isMySql = this.context.CurrentConnectionConfig.DbType.IsIn(DbType.MySql, DbType.MySqlConnector); var isSqliteCore = SugarCompatible.IsFramework==false&& this.context.CurrentConnectionConfig.DbType.IsIn(DbType.Sqlite); foreach (var item in datas) @@ -168,6 +180,15 @@ namespace SqlSugar } dr[name] = value; } + if (isDiscrimator && discrimatorDict?.Count > 0) + { + foreach (var dict in discrimatorDict) + { + var key = dict.Key; var val = dict.Value; + if (!string.IsNullOrWhiteSpace(val) && string.IsNullOrWhiteSpace(dr[key] + "")) + dr[key] = val; + } + } dt.Rows.Add(dr); } @@ -353,5 +374,24 @@ namespace SqlSugar } } + private (bool isDiscrimator, Dictionary discrimatorDict) GetDiscrimator() + { + var isDiscrimator = entityInfo.Discrimator.HasValue(); + var dict = new Dictionary(); + if (isDiscrimator) + { + Check.ExceptionEasy(!Regex.IsMatch(entityInfo.Discrimator, @"^(?:\w+:\w+)(?:,\w+:\w+)*$"), "The format should be type:cat for this type, and if there are multiple, it can be FieldName:cat,FieldName2:dog ", "格式错误应该是type:cat这种格式,如果是多个可以FieldName:cat,FieldName2:dog,不要有空格"); + var array = entityInfo.Discrimator.Split(','); + foreach (var disItem in array) + { + var name = disItem.Split(':').First(); + var value = disItem.Split(':').Last(); + dict.TryAdd(name, value); + } + } + + return (isDiscrimator, dict); + } + } } -- Gitee