diff --git a/Src/Asp.Net/PgSqlTest/UnitTest/UJsonFunc.cs b/Src/Asp.Net/PgSqlTest/UnitTest/UJsonFunc.cs index a172e8a0e..437b25d3e 100644 --- a/Src/Asp.Net/PgSqlTest/UnitTest/UJsonFunc.cs +++ b/Src/Asp.Net/PgSqlTest/UnitTest/UJsonFunc.cs @@ -1,8 +1,11 @@ -using Newtonsoft.Json.Linq; +using Microsoft.SqlServer.Server; +using Newtonsoft.Json.Linq; using SqlSugar; using System; using System.Collections.Generic; +using System.Data; using System.Linq; +using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; @@ -23,8 +26,8 @@ namespace OrmTest db.Insertable(new UnitJsonTest22() { A = JObject.Parse(db.Utilities.SerializeObject(new { Id = 2,hh=new string[] { "1","2"},zz=new { b=111} })) }).ExecuteCommand(); db.Insertable(new UnitJsonTest22() { A = JObject.Parse(db.Utilities.SerializeObject(new { Id = 2, zz = new { b = 222 } })) }).ExecuteCommand(); - + var list = db.Queryable() .Where(x =>Convert.ToInt32(SqlFunc.JsonField(x.A,"zz","b")) == 111) @@ -63,9 +66,52 @@ namespace OrmTest .Where(x => SqlFunc.JsonLike(x.A,"hh")) .ToList(); + db.DbMaintenance.DropTable(); + + db.CodeFirst.InitTables(); + db.DbMaintenance.TruncateTable(); + db.Insertable(new UnitJsonArray() { a = new int[] { 1, 2, 3 }, b = new string[] { "a", "b" } }).ExecuteCommand(); + db.Insertable(new UnitJsonArray() { a = new int[] { 5 }, b = new string[] { "c", "d" } }).ExecuteCommand(); + var isBool=db.Queryable().Any(it => SqlFunc.JsonArrayAny(it.a, 1)); + var isBool2 = db.Queryable().Any(it => SqlFunc.JsonArrayAny(it.a, 4)); + + var isBool1 = db.Queryable().Any(it => SqlFunc.JsonArrayAny(it.b, "a")); + var isBool22 = db.Queryable().Any(it => SqlFunc.JsonArrayAny(it.b, "e")); + + if (isBool == false || isBool2 == true || isBool1 == false || isBool22 == true) + { + throw new Exception("unit test"); + } + db.CodeFirst.InitTables(); + db.Insertable(new UnitJsonTest2222() { + A =JArray.Parse(db.Utilities.SerializeObject( new List() { new Order() { Id = 1, Name = "a" } }.ToList())) + }).ExecuteCommand(); + var isAny=db.Queryable().Any(it => SqlFunc.JsonListObjectAny(it.A, "Name", "a")); + var isAny2 = db.Queryable().Any(it => SqlFunc.JsonListObjectAny(it.A, "Name", "b")); + + var isAny21 = db.Queryable().Any(it => SqlFunc.JsonListObjectAny(it.A, "Id", 1)); + var isAny22 = db.Queryable().Any(it => SqlFunc.JsonListObjectAny(it.A, "Id", 2)); + + if (isAny == false || isAny21 == false || isAny2 == true || isAny22 == true) + { + throw new Exception("unit test"); + } } - public class UnitJsonTest22 + + public class UnitJsonArray + { + [SqlSugar.SugarColumn(IsJson =true)] + public int[] a { get; set; } + [SqlSugar.SugarColumn(IsJson = true)] + public string[] b { get; set; } + } + public class UnitJsonTest2222 + { + [SqlSugar.SugarColumn(IsJson = true)] + public JArray A { get; set; } + } + public class UnitJsonTest22 { [SqlSugar.SugarColumn(IsJson =true)] public JObject A { get; set; }