From 69abec9b9584d3a5988b4b6a20e2180548c846c1 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Fri, 3 Mar 2023 19:47:16 +0800 Subject: [PATCH] Add SqlServer json func --- .../SqlBuilder/SqlServerExpressionContext.cs | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Src/Asp.Net/SqlSugar/Realization/SqlServer/SqlBuilder/SqlServerExpressionContext.cs b/Src/Asp.Net/SqlSugar/Realization/SqlServer/SqlBuilder/SqlServerExpressionContext.cs index e619c06b9..7a5cb5081 100644 --- a/Src/Asp.Net/SqlSugar/Realization/SqlServer/SqlBuilder/SqlServerExpressionContext.cs +++ b/Src/Asp.Net/SqlSugar/Realization/SqlServer/SqlBuilder/SqlServerExpressionContext.cs @@ -1,4 +1,5 @@ -using System; +using Newtonsoft.Json.Linq; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; @@ -87,7 +88,22 @@ namespace SqlSugar private string GetJson(object memberName1, object memberName2, bool isLast) { - return $"JSON_VALUE({memberName1}, '$.'+"+memberName2+")"; + return $"JSON_VALUE({memberName1}, '$.'+" + memberName2 + ")"; + } + + public override string JsonListObjectAny(MethodCallExpressionModel model) + { + return $"(EXISTS (SELECT * from OPENJSON({model.Args[0].MemberName}) " + + $"WITH([value] NVARCHAR(MAX) '$.{model.Args[1].MemberValue.ToString().ToSqlFilter()}') " + + $"WHERE [value] = {model.Args[2].MemberName}))"; + } + + public override string JsonArrayAny(MethodCallExpressionModel model) + { + return string.Format("(EXISTS(SELECT * from OPENJSON({0}) WHERE [value] = {1}))" + , model.Args[0].MemberName + , model.Args[1].MemberName + ); } } -} +} \ No newline at end of file