From daa333192af7bf413d11d434810b03c0f1d754b2 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sun, 2 Jun 2019 10:42:18 +0800 Subject: [PATCH] Update demo --- Src/Asp.Net/SqlServerTest/Demo/Demo0_SqlSugarClient.cs | 8 ++++---- Src/Asp.Net/SqlServerTest/Demo/Demo1_Queryable.cs | 4 ++-- Src/Asp.Net/SqlServerTest/Models/Mapper.cs | 9 +++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Src/Asp.Net/SqlServerTest/Demo/Demo0_SqlSugarClient.cs b/Src/Asp.Net/SqlServerTest/Demo/Demo0_SqlSugarClient.cs index f0febcdae..8d3f7869d 100644 --- a/Src/Asp.Net/SqlServerTest/Demo/Demo0_SqlSugarClient.cs +++ b/Src/Asp.Net/SqlServerTest/Demo/Demo0_SqlSugarClient.cs @@ -46,10 +46,10 @@ namespace OrmTest //Use db var dt = db.Ado.GetDataTable("select 1"); - //create table OrderDetail - db.CodeFirst.InitTables(typeof(OrderItem)); - - db.Insertable(new OrderItem() { OrderId = 1, Price = 0 }).ExecuteCommand(); + //create tables + db.CodeFirst.InitTables(typeof(OrderItem),typeof(Order)); + var id = db.Insertable(new Order() { Name = "order1", CustomId = 1, Price = 0, CreateTime = DateTime.Now }).ExecuteReturnIdentity(); + db.Insertable(new OrderItem() { OrderId = id, Price = 0 }).ExecuteCommand(); Console.WriteLine("#### SqlSugarClient End ####"); } diff --git a/Src/Asp.Net/SqlServerTest/Demo/Demo1_Queryable.cs b/Src/Asp.Net/SqlServerTest/Demo/Demo1_Queryable.cs index bc6789f5c..b939042b5 100644 --- a/Src/Asp.Net/SqlServerTest/Demo/Demo1_Queryable.cs +++ b/Src/Asp.Net/SqlServerTest/Demo/Demo1_Queryable.cs @@ -148,8 +148,8 @@ namespace OrmTest //Child=(select * from parent where ParentId=it.id) .Mapper(it => it.Child, it => it.Id, it => it.Parent.ParentId) .ToList(); - - + //one to one + var list2 = db.Queryable().Mapper(it => it.Order, it => it.OrderId).ToList(); Console.WriteLine("#### End Start ####"); } diff --git a/Src/Asp.Net/SqlServerTest/Models/Mapper.cs b/Src/Asp.Net/SqlServerTest/Models/Mapper.cs index aad1195d1..a1402cfbc 100644 --- a/Src/Asp.Net/SqlServerTest/Models/Mapper.cs +++ b/Src/Asp.Net/SqlServerTest/Models/Mapper.cs @@ -5,16 +5,17 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace OrmTest.Models +namespace OrmTest { [SugarTable("OrderDetail")] public class OrderItemInfo { - [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)] public int ItemId { get; set; } - public string ItemCode { get; set; } - public decimal Pirce { get; set; } public int OrderId { get; set; } + public decimal? Price { get; set; } + [SqlSugar.SugarColumn(IsNullable = true)] + public DateTime? CreateTime { get; set; } [SugarColumn(IsIgnore = true)] public Order Order { get; set; } }