Browse Source

Update demo

pull/12/MERGE
sunkaixuan 6 years ago
parent
commit
daa333192a
  1. 8
      Src/Asp.Net/SqlServerTest/Demo/Demo0_SqlSugarClient.cs
  2. 4
      Src/Asp.Net/SqlServerTest/Demo/Demo1_Queryable.cs
  3. 9
      Src/Asp.Net/SqlServerTest/Models/Mapper.cs

8
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 ####");
}

4
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<OrderItemInfo>().Mapper(it => it.Order, it => it.OrderId).ToList();
Console.WriteLine("#### End Start ####");
}

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

Loading…
Cancel
Save