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; } }