From cd915a7883d20a58218360cd02d3c09aa15bb61e Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Wed, 21 Sep 2022 18:27:00 +0800 Subject: [PATCH] Add unit test --- .../SqlSeverTest/UnitTest/Main.cs | 2 +- .../SqlSeverTest/UnitTest/UJsonsdafa.cs | 58 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 Src/Asp.NetCore2/SqlSeverTest/UnitTest/UJsonsdafa.cs diff --git a/Src/Asp.NetCore2/SqlSeverTest/UnitTest/Main.cs b/Src/Asp.NetCore2/SqlSeverTest/UnitTest/Main.cs index d30d27945..d70852429 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/UnitTest/Main.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/UnitTest/Main.cs @@ -31,7 +31,7 @@ namespace OrmTest } public static void Init() { - + UJsonsdafa.Init(); UOneManyMany.init(); UOneManyMany2.init(); UOneManyMany3.init(); diff --git a/Src/Asp.NetCore2/SqlSeverTest/UnitTest/UJsonsdafa.cs b/Src/Asp.NetCore2/SqlSeverTest/UnitTest/UJsonsdafa.cs new file mode 100644 index 000000000..a97992bb3 --- /dev/null +++ b/Src/Asp.NetCore2/SqlSeverTest/UnitTest/UJsonsdafa.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Text; +using SqlSugar; +namespace OrmTest +{ + public class UJsonsdafa + { + public static void Init() + { + + + SqlSugarClient db = NewUnitTest.Db; + if (!db.DbMaintenance.IsAnyTable("t1", false)) + { + db.CodeFirst.InitTables(); + db.CodeFirst.InitTables(); + var result1 = db.Insertable(new t1 { id = 1, f1 = "f1" }).ExecuteCommand(); + var result2 = db.Insertable(new t2 + { + id = 1, + json1 = new field_t2_json1 { a = "a", b = "b", c = new field_t2_f1_c() { x = "x", y = "y" } }, + json2 = null + }).ExecuteCommand(); + } + + var list0 = db.Queryable().InnerJoin((m, j) => m.id == j.id).Where((m) => m.id == 1).Select((m, j) => new { m, j.json1, j.json2 }).ToList(); + Console.WriteLine(string.Format("{0}:{1}", list0[0].json1.a, list0[0].json1.c.x)); //可以得到json1的值 + } + public class t1 + { + [SugarColumn(IsPrimaryKey = true)] + public int id { get; set; } + public string f1 { get; set; } + } + public class t2 + { + [SugarColumn(IsPrimaryKey = true)] + public int id { get; set; } + [SugarColumn(IsJson = true, IsNullable = true)] + public field_t2_json1 json1 { get; set; } + [SugarColumn(IsJson = true, IsNullable = true)] + public Dictionary json2 { get; set; } + } + public class field_t2_json1 + { + public string a { get; set; } + public string b { get; set; } + [SugarColumn(IsJson = true, IsNullable = true)] + public field_t2_f1_c c { get; set; } + } + public class field_t2_f1_c + { + public string x { get; set; } + public string y { get; set; } + } + } +}