mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 13:06:50 +08:00
Add unit test
This commit is contained in:
parent
cf52d5d3a8
commit
cd915a7883
@ -31,7 +31,7 @@ namespace OrmTest
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
|
||||
UJsonsdafa.Init();
|
||||
UOneManyMany.init();
|
||||
UOneManyMany2.init();
|
||||
UOneManyMany3.init();
|
||||
|
58
Src/Asp.NetCore2/SqlSeverTest/UnitTest/UJsonsdafa.cs
Normal file
58
Src/Asp.NetCore2/SqlSeverTest/UnitTest/UJsonsdafa.cs
Normal file
@ -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<t1>();
|
||||
db.CodeFirst.InitTables<t2>();
|
||||
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<t1>().InnerJoin<t2>((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<string, string> 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; }
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user