From f02e9a3ea9b7e28c3fe228390eff090a85802e2f Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Tue, 14 Jun 2022 19:01:35 +0800 Subject: [PATCH] Update .net core project --- .../ExpressionsToSql/Common/SugarParameter.cs | 5 ++++- .../SqlSugar/Interface/ISimpleClient.cs | 4 ++++ Src/Asp.NetCore2/SqlSugar/SimpleClient.cs | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Common/SugarParameter.cs b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Common/SugarParameter.cs index 0e6baeb18..a1484258d 100644 --- a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Common/SugarParameter.cs +++ b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Common/SugarParameter.cs @@ -136,7 +136,10 @@ namespace SqlSugar else if (type!=null&&type.IsEnum()) { this.DbType = System.Data.DbType.Int64; - this.Value = Convert.ToInt64(Value); + if (Value != null) + { + this.Value = Convert.ToInt64(Value); + } } else if (type==UtilConstants.UIntType) { diff --git a/Src/Asp.NetCore2/SqlSugar/Interface/ISimpleClient.cs b/Src/Asp.NetCore2/SqlSugar/Interface/ISimpleClient.cs index 2d048ed34..7b3d89259 100644 --- a/Src/Asp.NetCore2/SqlSugar/Interface/ISimpleClient.cs +++ b/Src/Asp.NetCore2/SqlSugar/Interface/ISimpleClient.cs @@ -36,6 +36,8 @@ namespace SqlSugar T GetSingle(Expression> whereExpression); T GetFirst(Expression> whereExpression); bool Insert(T insertObj); + bool InsertOrUpdate(T data); + bool InsertOrUpdate(List datas); bool InsertRange(List insertObjs); bool InsertRange(T[] insertObjs); int InsertReturnIdentity(T insertObj); @@ -69,6 +71,8 @@ namespace SqlSugar Task GetSingleAsync(Expression> whereExpression); Task GetFirstAsync(Expression> whereExpression); Task InsertAsync(T insertObj); + Task InsertOrUpdateAsync(T data); + Task InsertOrUpdateAsync(List datas); Task InsertRangeAsync(List insertObjs); Task InsertRangeAsync(T[] insertObjs); Task InsertReturnIdentityAsync(T insertObj); diff --git a/Src/Asp.NetCore2/SqlSugar/SimpleClient.cs b/Src/Asp.NetCore2/SqlSugar/SimpleClient.cs index 758226072..c3c9059f6 100644 --- a/Src/Asp.NetCore2/SqlSugar/SimpleClient.cs +++ b/Src/Asp.NetCore2/SqlSugar/SimpleClient.cs @@ -148,6 +148,16 @@ namespace SqlSugar { return this.Context.Insertable(insertObj).ExecuteCommand() > 0; } + + public virtual bool InsertOrUpdate(T data) + { + return this.Context.Storageable(data).ExecuteCommand() > 0; + } + public virtual bool InsertOrUpdate(List datas) + { + return this.Context.Storageable(datas).ExecuteCommand() > 0; + } + public virtual int InsertReturnIdentity(T insertObj) { return this.Context.Insertable(insertObj).ExecuteReturnIdentity(); @@ -278,6 +288,14 @@ namespace SqlSugar return Context.Queryable().Where(whereExpression).CountAsync(); } + public virtual async Task InsertOrUpdateAsync(T data) + { + return await this.Context.Storageable(data).ExecuteCommandAsync() > 0; + } + public virtual async Task InsertOrUpdateAsync(List datas) + { + return await this.Context.Storageable(datas).ExecuteCommandAsync() > 0; + } public virtual async Task InsertAsync(T insertObj) { return await this.Context.Insertable(insertObj).ExecuteCommandAsync() > 0;