From 72e829f4b7ea9b164d85bb3ced77921450c0e930 Mon Sep 17 00:00:00 2001 From: sunkaixuna <610262374@qq.com> Date: Tue, 23 Nov 2021 18:38:58 +0800 Subject: [PATCH] Update core --- .../SplitCodeFirstProvider.cs | 2 +- .../FastestProvider/FastestProvider.cs | 18 ++++++++------- .../Abstract/FastestProvider/Private.cs | 2 +- .../Abstract/SaveableProvider/Storageable.cs | 3 +++ .../SqlSugar/Interface/IStorageable.cs | 23 +++++++++++++++++++ 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/SplitCodeFirstProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/SplitCodeFirstProvider.cs index 181d5ba53..9f9f0fa08 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/SplitCodeFirstProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/SplitCodeFirstProvider.cs @@ -41,7 +41,7 @@ namespace SqlSugar this.Context.MappingTables.Add(helper.EntityInfo.EntityName, helper.EntityInfo.DbTableName); } - public void InitTables(Type [] types) + public void InitTables(Type [] types) { foreach (var type in types) { diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/FastestProvider/FastestProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/FastestProvider/FastestProvider.cs index 4e133d0a3..a2edd1935 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/FastestProvider/FastestProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/FastestProvider/FastestProvider.cs @@ -79,7 +79,7 @@ namespace SqlSugar #region Core private async Task _BulkUpdate(List datas, string[] whereColumns, string[] updateColumns) { - Begin(datas); + Begin(datas,false); Check.Exception(whereColumns == null || whereColumns.Count() == 0, "where columns count=0 or need primary key"); Check.Exception(updateColumns == null || updateColumns.Count() == 0, "set columns count=0"); var isAuto = this.context.CurrentConnectionConfig.IsAutoCloseConnection; @@ -94,38 +94,40 @@ namespace SqlSugar this.context.DbMaintenance.DropTable(dt.TableName); this.context.CurrentConnectionConfig.IsAutoCloseConnection = isAuto; buider.CloseDb(); - End(datas); + End(datas, false); return result; } private async Task _BulkCopy(List datas) { - Begin(datas); + Begin(datas,true); DataTable dt = ToDdateTable(datas); IFastBuilder buider =GetBuider(); buider.Context = context; var result = await buider.ExecuteBulkCopyAsync(dt); - End(datas); + End(datas,true); return result; } #endregion #region AOP - private void End(List datas) + private void End(List datas,bool isAdd) { + var title = isAdd ? "BulkCopy" : "BulkUpdate"; this.context.Ado.IsEnableLogEvent = isLog; if (this.context.CurrentConnectionConfig?.AopEvents?.OnLogExecuted != null) { - this.context.CurrentConnectionConfig?.AopEvents?.OnLogExecuted($"End bulkcopy name:{entityInfo.DbTableName} ,count: {datas.Count},current time: {DateTime.Now}" , new SugarParameter[] { }); + this.context.CurrentConnectionConfig?.AopEvents?.OnLogExecuted($"End {title} name:{entityInfo.DbTableName} ,count: {datas.Count},current time: {DateTime.Now}" , new SugarParameter[] { }); } } - private void Begin(List datas) + private void Begin(List datas,bool isAdd) { + var title = isAdd ? "BulkCopy" : "BulkUpdate"; isLog = this.context.Ado.IsEnableLogEvent; this.context.Ado.IsEnableLogEvent = false; if (this.context.CurrentConnectionConfig?.AopEvents?.OnLogExecuting != null) { - this.context.CurrentConnectionConfig?.AopEvents?.OnLogExecuting($"Begin bulkcopy name:{entityInfo.DbTableName} ,count: {datas.Count},current time: {DateTime.Now} ", new SugarParameter[] { }); + this.context.CurrentConnectionConfig?.AopEvents?.OnLogExecuting($"Begin {title} name:{entityInfo.DbTableName} ,count: {datas.Count},current time: {DateTime.Now} ", new SugarParameter[] { }); } } #endregion diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/FastestProvider/Private.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/FastestProvider/Private.cs index bfdbecf39..d8795ec16 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/FastestProvider/Private.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/FastestProvider/Private.cs @@ -92,7 +92,7 @@ namespace SqlSugar private object ValueConverter(EntityColumnInfo columnInfo, object value) { if (value == null) - return value; + return DBNull.Value; if (value is DateTime && (DateTime)value == DateTime.MinValue) { value = Convert.ToDateTime("1900-01-01"); diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SaveableProvider/Storageable.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SaveableProvider/Storageable.cs index 336a37dae..16024daa1 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SaveableProvider/Storageable.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SaveableProvider/Storageable.cs @@ -125,6 +125,9 @@ namespace SqlSugar var other = messageList.Where(it => it.StorageType == StorageType.Other).ToList(); StorageableResult result = new StorageableResult() { + _IsWhereColumn= this.whereExpression != null, + _AsName =asname, + _Context=this.Context, AsDeleteable = this.Context.Deleteable().AS(asname), AsUpdateable = this.Context.Updateable(update.Select(it => it.Item).ToList()).AS(asname), AsInsertable = this.Context.Insertable(inset.Select(it => it.Item).ToList()).AS(asname), diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IStorageable.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IStorageable.cs index 090f64fd8..823cea16b 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IStorageable.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IStorageable.cs @@ -88,5 +88,28 @@ namespace SqlSugar public IInsertable AsInsertable { get; set; } public IUpdateable AsUpdateable { get; set; } public IDeleteable AsDeleteable { get; set; } + internal bool _IsWhereColumn { get; set; } + internal string _AsName { get; set; } + internal SqlSugarProvider _Context { get; set; } + + public int BulkCopy() + { + return this._Context.Fastest().AS(_AsName).BulkCopy(InsertList.Select(it=>it.Item).ToList()); + } + public Task BulkCopyAsync() + { + return this._Context.Fastest().AS(_AsName).BulkCopyAsync(InsertList.Select(it => it.Item).ToList()); + } + + public int BulkUpdate() + { + Check.Exception(_IsWhereColumn, "Storageable.BulkCopy no support WhereColumns"); + return this._Context.Fastest().AS(_AsName).BulkUpdate(UpdateList.Select(it => it.Item).ToList()); + } + public Task BulkUpdateAsync() + { + Check.Exception(_IsWhereColumn, "Storageable.BulkCopy no support WhereColumns"); + return this._Context.Fastest().AS(_AsName).BulkUpdateAsync(UpdateList.Select(it => it.Item).ToList()); + } } }