From 8bd3647322d6da838222ae2cf910ea3bd95b4bd2 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Mon, 7 Apr 2025 19:09:56 +0800 Subject: [PATCH] Update Dynamic.Core --- .../SqlSugar/Entities/DynamicSelectModel.cs | 99 ++++++++++++------- 1 file changed, 65 insertions(+), 34 deletions(-) diff --git a/Src/Asp.NetCore2/SqlSugar/Entities/DynamicSelectModel.cs b/Src/Asp.NetCore2/SqlSugar/Entities/DynamicSelectModel.cs index ac47b7ba4..14916d388 100644 --- a/Src/Asp.NetCore2/SqlSugar/Entities/DynamicSelectModel.cs +++ b/Src/Asp.NetCore2/SqlSugar/Entities/DynamicSelectModel.cs @@ -10,39 +10,6 @@ namespace SqlSugar public class DynamicCoreSelectModel { public object Value { get; set; } - public object InSingle(object value) - { - if (Value is null) - { - throw new InvalidOperationException("Value cannot be null."); - } - - var method = Value.GetType().GetMyMethod("InSingle", 1); - if (method == null) - { - throw new InvalidOperationException("The Value object does not have an InSingle method with one parameter."); - } - - return method.Invoke(Value, new object[] { value }); - } - - public async Task InSingleAsync(object value) - { - if (Value is null) - { - throw new InvalidOperationException("Value cannot be null."); - } - - var method = Value.GetType().GetMyMethod("InSingleAsync", 1); - if (method == null) - { - throw new InvalidOperationException("The Value object does not have an InSingleAsync method with one parameter."); - } - - var task = (Task)method.Invoke(Value, new object[] { value }); - return await GetTask(task).ConfigureAwait(false); - } - public object ToList() { @@ -148,12 +115,76 @@ namespace SqlSugar totalNumber = (int)parameters[2]; return result; } + public object Single() + { + if (Value is null) + { + throw new InvalidOperationException("Value cannot be null."); + } + var method = Value.GetType().GetMyMethod("Single", 0); + if (method == null) + { + throw new InvalidOperationException("The Value object does not have a Single method with no parameters."); + } + + return method.Invoke(Value, null); + } + public object First() + { + if (Value is null) + { + throw new InvalidOperationException("Value cannot be null."); + } + + var method = Value.GetType().GetMyMethod("First", 0); + if (method == null) + { + throw new InvalidOperationException("The Value object does not have a First method with no parameters."); + } + + return method.Invoke(Value, null); + } + + public async Task SingleAsync() + { + if (Value is null) + { + throw new InvalidOperationException("Value cannot be null."); + } + + var method = Value.GetType().GetMyMethod("SingleAsync", 0); + if (method == null) + { + throw new InvalidOperationException("The Value object does not have a SingleAsync method with no parameters."); + } + + var task = (Task)method.Invoke(Value, null); + return await GetTask(task).ConfigureAwait(false); + } + + public async Task FirstAsync() + { + if (Value is null) + { + throw new InvalidOperationException("Value cannot be null."); + } + + var method = Value.GetType().GetMyMethod("FirstAsync", 0); + if (method == null) + { + throw new InvalidOperationException("The Value object does not have a FirstAsync method with no parameters."); + } + + var task = (Task)method.Invoke(Value, null); + return await GetTask(task).ConfigureAwait(false); + } + private static async Task GetTask(Task task) { await task.ConfigureAwait(false); // 等待任务完成 var resultProperty = task.GetType().GetProperty("Result"); - var value = resultProperty.GetValue(task); + var value = resultProperty.GetValue(task); return value; } }