From 3a11e63f1ba44e3618cb6a2a0a54f3599a4bb2ca Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Mon, 20 Jun 2022 13:56:12 +0800 Subject: [PATCH] Update json 2 sql demo --- Src/Asp.Net/Json2SqlTest/Program.cs | 4 +-- Src/Asp.Net/Json2SqlTest/Table.cs | 40 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 Src/Asp.Net/Json2SqlTest/Table.cs diff --git a/Src/Asp.Net/Json2SqlTest/Program.cs b/Src/Asp.Net/Json2SqlTest/Program.cs index 36dadeaaa..9e9e945f8 100644 --- a/Src/Asp.Net/Json2SqlTest/Program.cs +++ b/Src/Asp.Net/Json2SqlTest/Program.cs @@ -21,6 +21,8 @@ namespace Test IsAutoCloseConnection = true, ConnectionString = "server=localhost;Database=SqlSugar4xTest;Uid=root;Pwd=haosql" }); ; + TestHelper.InitDatabase(jsonToSqlClient); + jsonToSqlClient.Context.Aop.OnLogExecuted = (sql, p) => { Console.WriteLine(sql); @@ -45,7 +47,5 @@ namespace Test Console.WriteLine(); } - - } } diff --git a/Src/Asp.Net/Json2SqlTest/Table.cs b/Src/Asp.Net/Json2SqlTest/Table.cs new file mode 100644 index 000000000..3f71d04e5 --- /dev/null +++ b/Src/Asp.Net/Json2SqlTest/Table.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Text; +using SqlSugar; +namespace Test +{ + public static class TestHelper + { + + public static void InitDatabase(JsonClient jsonToSqlClient) + { + jsonToSqlClient.Context.DbMaintenance.CreateDatabase();//创建测试库 Create test database + jsonToSqlClient.Context.CodeFirst.InitTables();//创建测试表 Create test table + } + } + public class Order + { + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int Id { get; set; } + + public string Name { get; set; } + public decimal Price { get; set; } + [SugarColumn(IsNullable = true)] + public DateTime CreateTime { get; set; } + [SugarColumn(IsNullable = true)] + public int CustomId { get; set; } + [SugarColumn(IsIgnore = true)] + public List Items { get; set; } + } + [SqlSugar.SugarTable("OrderDetail")] + public class OrderItem + { + [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int ItemId { get; set; } + public int OrderId { get; set; } + public decimal? Price { get; set; } + [SqlSugar.SugarColumn(IsNullable = true)] + public DateTime? CreateTime { get; set; } + } +}