From 1be2b165d0e1b853befc79b574ead996a2b85956 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Tue, 23 Jan 2024 17:31:16 +0800 Subject: [PATCH] Update json 2 sql --- Src/Asp.NetCore2/Json2Sql/QueryableTest.cs | 11 ++++++++--- .../Json2Sql/ModelToSql/FuncModelToSql.cs | 17 ++++++++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Src/Asp.NetCore2/Json2Sql/QueryableTest.cs b/Src/Asp.NetCore2/Json2Sql/QueryableTest.cs index 552c96e7f..68efec752 100644 --- a/Src/Asp.NetCore2/Json2Sql/QueryableTest.cs +++ b/Src/Asp.NetCore2/Json2Sql/QueryableTest.cs @@ -167,14 +167,19 @@ namespace Test new SelectModel() { AsName = "id1", - FiledName = "id" + FieldName = "id" }, new SelectModel() { - FiledName = "id" + FieldName = ObjectFuncModel.Create("MergeString", new string[] { + "Name", + "Name" + } + ) , + AsName="Name" } - }; + }; jsonToSqlClient.Context .Queryable() .AS("order").Select(list).ToList(); diff --git a/Src/Asp.NetCore2/SqlSugar/Json2Sql/ModelToSql/FuncModelToSql.cs b/Src/Asp.NetCore2/SqlSugar/Json2Sql/ModelToSql/FuncModelToSql.cs index 63270d077..6eddad6a2 100644 --- a/Src/Asp.NetCore2/SqlSugar/Json2Sql/ModelToSql/FuncModelToSql.cs +++ b/Src/Asp.NetCore2/SqlSugar/Json2Sql/ModelToSql/FuncModelToSql.cs @@ -54,6 +54,10 @@ namespace SqlSugar { resSql = GetSqlFuncSql(parameters, dbMethods, methodName, methodInfo, resPars); } + else if (IsMergeStringMethod(methodName)) + { + resSql = GetSqlFuncSql(parameters, dbMethods, methodName, methodInfo, resPars); + } else { resSql = GetNoSupportMethodSql(methodInfo); @@ -61,6 +65,8 @@ namespace SqlSugar return resSql; } + + private static System.Reflection.MethodInfo GetMethod(IDbMethods dbMethods, string methodName) { return dbMethods.GetType().GetMethods() @@ -114,6 +120,10 @@ namespace SqlSugar IsMember = true }); } + if (IsMergeStringMethod(methodName)) + { + return methodInfo.Invoke(dbMethods, new object[] { args.Select(it=>it.MemberName.ObjToString()).ToArray() }).ObjToString(); + } resSql = methodInfo.Invoke(dbMethods, new object[] { new MethodCallExpressionModel() { Name=methodName, Args=args @@ -135,10 +145,15 @@ namespace SqlSugar private static string GetNoParameterMehtodSql(IDbMethods dbMethods, System.Reflection.MethodInfo methodInfo) { return methodInfo.Invoke(dbMethods, new object[] { }).ObjToString(); - } + } #endregion #region Helper + private static bool IsMergeStringMethod(string methodName) + { + return methodName == "MergeString"; + } + private static bool IsSqlFuncMethod(System.Reflection.ParameterInfo[] pars) { return pars.First().ParameterType == typeof(MethodCallExpressionModel);