From 5e9be3c1e93b2df7d50c160fc76a6eb101702380 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Mon, 20 Jun 2022 13:49:57 +0800 Subject: [PATCH] Update json 2 sql demo --- Src/Asp.NetCore2/Json2Sql/Program.cs | 4 +-- Src/Asp.NetCore2/Json2Sql/Table.cs | 40 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 Src/Asp.NetCore2/Json2Sql/Table.cs diff --git a/Src/Asp.NetCore2/Json2Sql/Program.cs b/Src/Asp.NetCore2/Json2Sql/Program.cs index 36dadeaaa..9e9e945f8 100644 --- a/Src/Asp.NetCore2/Json2Sql/Program.cs +++ b/Src/Asp.NetCore2/Json2Sql/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.NetCore2/Json2Sql/Table.cs b/Src/Asp.NetCore2/Json2Sql/Table.cs new file mode 100644 index 000000000..3f71d04e5 --- /dev/null +++ b/Src/Asp.NetCore2/Json2Sql/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; } + } +}