From 02d3400cd6b30be87ca05d0c08dcc45bfa3b7711 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Wed, 15 Feb 2023 15:30:42 +0800 Subject: [PATCH] Add db.UpdateableByObject(o).ExecuteCommandAsync() --- Src/Asp.Net/SqlServerTest/Demo/Demo1_Queryable.cs | 2 +- Src/Asp.Net/SqlServerTest/Demo/Demo2_Updateable.cs | 2 +- Src/Asp.Net/SqlServerTest/Demo/Demo3_Insertable.cs | 2 +- .../SqlSugar/Abstract/UpdateProvider/UpdateMethodInfo.cs | 9 +++++++++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Src/Asp.Net/SqlServerTest/Demo/Demo1_Queryable.cs b/Src/Asp.Net/SqlServerTest/Demo/Demo1_Queryable.cs index e0ccfcefc..b3a6bd7fc 100644 --- a/Src/Asp.Net/SqlServerTest/Demo/Demo1_Queryable.cs +++ b/Src/Asp.Net/SqlServerTest/Demo/Demo1_Queryable.cs @@ -286,7 +286,7 @@ namespace OrmTest Console.WriteLine(""); Console.WriteLine("#### Subquery Start ####"); var db = GetInstance(); - + var list = db.Queryable().Take(10).Select(it => new { customName = SqlFunc.Subqueryable().Where("it.CustomId=id").Select(s => s.Name), diff --git a/Src/Asp.Net/SqlServerTest/Demo/Demo2_Updateable.cs b/Src/Asp.Net/SqlServerTest/Demo/Demo2_Updateable.cs index 2d1ad3ac5..0c9a99f61 100644 --- a/Src/Asp.Net/SqlServerTest/Demo/Demo2_Updateable.cs +++ b/Src/Asp.Net/SqlServerTest/Demo/Demo2_Updateable.cs @@ -136,7 +136,7 @@ namespace OrmTest object o = db.Queryable().First(); - db.UpdateableByObject(o).ExecuteCommand(); + db.UpdateableByObject(o).ExecuteCommandAsync().GetAwaiter().GetResult(); object os = db.Queryable().Take(2).ToList(); db.UpdateableByObject(os).ExecuteCommand(); Console.WriteLine("#### Updateable End ####"); diff --git a/Src/Asp.Net/SqlServerTest/Demo/Demo3_Insertable.cs b/Src/Asp.Net/SqlServerTest/Demo/Demo3_Insertable.cs index 07d6ae14b..3a88a293e 100644 --- a/Src/Asp.Net/SqlServerTest/Demo/Demo3_Insertable.cs +++ b/Src/Asp.Net/SqlServerTest/Demo/Demo3_Insertable.cs @@ -86,7 +86,7 @@ namespace OrmTest int result2 = db.Fastest().AS("order").BulkCopy( dataTable); object o = db.Queryable().First(); - db.InsertableByObject(o).ExecuteCommand(); + db.InsertableByObject(o).ExecuteCommandAsync().GetAwaiter().GetResult(); object os = db.Queryable().Take(2).ToList(); db.InsertableByObject(os).ExecuteCommand(); diff --git a/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateMethodInfo.cs b/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateMethodInfo.cs index 74e0f095c..05ffb5c25 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateMethodInfo.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateMethodInfo.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Generic; using System.Reflection; using System.Text; +using System.Threading.Tasks; namespace SqlSugar { @@ -19,5 +20,13 @@ namespace SqlSugar var result= inertable.GetType().GetMethod("ExecuteCommand").Invoke(inertable,new object[] { }); return (int)result; } + + public async Task ExecuteCommandAsync() + { + if (Context == null) return 0; + var inertable = MethodInfo.Invoke(Context, new object[] { objectValue }); + var result = inertable.GetType().GetMethod("ExecuteCommandAsync").Invoke(inertable, new object[] { }); + return await (Task)result; + } } }