mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-05 17:37:58 +08:00
Update json 2 sql demo
This commit is contained in:
parent
cd366b8bd1
commit
5e9be3c1e9
Src/Asp.NetCore2/Json2Sql
@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
40
Src/Asp.NetCore2/Json2Sql/Table.cs
Normal file
40
Src/Asp.NetCore2/Json2Sql/Table.cs
Normal file
@ -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<Order, OrderItem>();//创建测试表 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<OrderItem> 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; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user