Browse Source

Add demo

pull/30/head
sunkaixuan 2 years ago
parent
commit
7c5b07486f
  1. 166
      Src/Asp.Net/SqlServerTest/Demo/Demo3_Insertable.cs

166
Src/Asp.Net/SqlServerTest/Demo/Demo3_Insertable.cs

@ -84,169 +84,15 @@ namespace OrmTest
var dataTable= db.Queryable<Order>().Select("id,name,Price").Take(2).ToDataTable();
int result= db.Fastest<System.Data.DataTable>().AS("order").BulkCopy("order", dataTable);
int result2 = db.Fastest<System.Data.DataTable>().AS("order").BulkCopy( dataTable);
object o = db.Queryable<Order>().First();
db.InsertableByObject(o).ExecuteCommand();
object os = db.Queryable<Order>().Take(2).ToList();
db.InsertableByObject(os).ExecuteCommand();
Console.WriteLine("#### Insertable End ####");
}
private static void SubNoIdentity(SqlSugarClient db)
{
db.CodeFirst.InitTables<Country, Province, City>();
db.DbMaintenance.TruncateTable("Country");
db.DbMaintenance.TruncateTable("Province");
db.DbMaintenance.TruncateTable("City");
db.Insertable(new List<Country>()
{
new Country(){
Id=1,
Name="中国",
Provinces=new List<Province>(){
new Province{
Id=1001,
Name="江苏",
citys=new List<City>(){
new City(){ Id=1001001, Name="南通" },
new City(){ Id=1001002, Name="南京" }
}
},
new Province{
Id=1002,
Name="上海",
citys=new List<City>(){
new City(){ Id=1002001, Name="徐汇" },
new City(){ Id=1002002, Name="普陀" }
}
},
new Province{
Id=1003,
Name="北京",
citys=new List<City>(){
new City(){ Id=1003001, Name="北京A" },
new City(){ Id=1003002, Name="北京B" }
}
}
}
},
new Country(){
Name="美国",
Id=2,
Provinces=new List<Province>()
{
new Province(){
Name="美国小A",
Id=20001
},
new Province(){
Name="美国小b",
Id=20002
}
}
},
new Country(){
Name="英国",
Id=3
}
})
.AddSubList(it => new SubInsertTree()
{
Expression = it.Provinces.First().CountryId,
ChildExpression = new List<SubInsertTree>() {
new SubInsertTree(){
Expression=it.Provinces.First().citys.First().ProvinceId
}
}
})
.ExecuteCommand();
var list = db.Queryable<Country>()
.Mapper(it => it.Provinces, it => it.Provinces.First().CountryId)
.Mapper(it =>
{
foreach (var item in it.Provinces)
{
item.citys = db.Queryable<City>().Where(y => y.ProvinceId == item.Id).ToList();
}
})
.ToList();
}
private static void SubIdentity(SqlSugarClient db)
{
db.CodeFirst.InitTables<Country1, Province1, City1>();
db.DbMaintenance.TruncateTable("Country1");
db.DbMaintenance.TruncateTable("Province1");
db.DbMaintenance.TruncateTable("City1");
db.Insertable(new List<Country1>()
{
new Country1(){
Id=1,
Name="中国",
Provinces=new List<Province1>(){
new Province1{
Id=1001,
Name="江苏",
citys=new List<City1>(){
new City1(){ Id=1001001, Name="南通" },
new City1(){ Id=1001002, Name="南京" }
}
},
new Province1{
Id=1002,
Name="上海",
citys=new List<City1>(){
new City1(){ Id=1002001, Name="徐汇" },
new City1(){ Id=1002002, Name="普陀" }
}
},
new Province1{
Id=1003,
Name="北京",
citys=new List<City1>(){
new City1(){ Id=1003001, Name="北京A" },
new City1(){ Id=1003002, Name="北京B" }
}
}
}
},
new Country1(){
Name="美国",
Id=2,
Provinces=new List<Province1>()
{
new Province1(){
Name="美国小A",
Id=20001
},
new Province1(){
Name="美国小b",
Id=20002
}
}
},
new Country1(){
Name="英国",
Id=3
}
})
.AddSubList(it => new SubInsertTree()
{
Expression = it.Provinces.First().CountryId,
ChildExpression = new List<SubInsertTree>() {
new SubInsertTree(){
Expression=it.Provinces.First().citys.First().ProvinceId
}
}
})
.ExecuteCommand();
var list = db.Queryable<Country1>()
.Mapper(it => it.Provinces, it => it.Provinces.First().CountryId)
.Mapper(it =>
{
foreach (var item in it.Provinces)
{
item.citys = db.Queryable<City1>().Where(y => y.ProvinceId == item.Id).ToList();
}
})
.ToList();
}
}
}

Loading…
Cancel
Save