mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-05 17:37:58 +08:00
Update demo
This commit is contained in:
parent
d6cb644a07
commit
da1c86f02e
@ -29,7 +29,7 @@ namespace OrmTest
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//建库
|
||||
db.DbMaintenance.CreateDatabase();
|
||||
|
||||
@ -38,26 +38,56 @@ namespace OrmTest
|
||||
|
||||
//创建子表
|
||||
db.Ado.ExecuteCommand(@"create table IF NOT EXISTS MyTable02 using St01 tags('California.SanFrancisco',1)");
|
||||
|
||||
|
||||
|
||||
//查询子表
|
||||
var dt = db.Ado.GetDataTable("select * from MyTable02 ");
|
||||
|
||||
|
||||
//插入子表
|
||||
//插入单条子表
|
||||
db.Insertable(new MyTable02()
|
||||
{
|
||||
ts = DateTime.Now,
|
||||
current = Convert.ToSingle(1.1),
|
||||
groupId = 1,
|
||||
isdelete=true,
|
||||
name="haha",
|
||||
isdelete = true,
|
||||
name = "haha",
|
||||
location = "aa",
|
||||
phase = Convert.ToSingle(1.1),
|
||||
phase = Convert.ToSingle(1.2),
|
||||
voltage = 11
|
||||
}).ExecuteCommand();
|
||||
|
||||
db.Insertable(new List<MyTable02>() {
|
||||
//批量插入子表
|
||||
db.Insertable(GetInsertDatas()).ExecuteCommand();
|
||||
|
||||
|
||||
//查询子表(主表字段也能查出来)
|
||||
var list = db.Queryable<MyTable02>().OrderBy(it => it.ts).ToList();
|
||||
|
||||
//条件查询
|
||||
var list2 = db.Queryable<MyTable02>().Where(it => it.name== "测试2").ToList();
|
||||
var list22 = db.Queryable<MyTable02>().Where(it => it.voltage == 222).ToList();
|
||||
var list222 = db.Queryable<MyTable02>().Where(it => it.phase == 1.2).ToList();
|
||||
var list2222 = db.Queryable<MyTable02>().Where(it => it.isdelete==true).ToList();
|
||||
|
||||
//模糊查询
|
||||
var list3 = db.Queryable<MyTable02>().Where(it => it.name.Contains("a")).ToList();
|
||||
|
||||
|
||||
//分页
|
||||
var Count = 0;
|
||||
var list4 = db.Queryable<MyTable02>().Where(it => it.voltage == 111)
|
||||
.ToPageList(1, 2, ref Count);
|
||||
|
||||
//删除子表
|
||||
var ts = list.First().ts;
|
||||
var de = DateTime.Now.AddYears(-1);
|
||||
var count = db.Deleteable<MyTable02>().Where(it => it.ts > de).ExecuteCommand();
|
||||
}
|
||||
|
||||
private static List<MyTable02> GetInsertDatas()
|
||||
{
|
||||
return new List<MyTable02>() {
|
||||
new MyTable02()
|
||||
{
|
||||
ts = DateTime.Now.AddDays(-1),
|
||||
@ -91,28 +121,7 @@ namespace OrmTest
|
||||
phase = Convert.ToSingle(1.1),
|
||||
voltage = 111
|
||||
}
|
||||
}).ExecuteCommand();
|
||||
|
||||
|
||||
//查询子表(主表字段也能查出来)
|
||||
var list = db.Queryable<MyTable02>().OrderBy(it=>it.ts).ToList();
|
||||
|
||||
//条件查询
|
||||
var list2 = db.Queryable<MyTable02>().Where(it=>it.voltage==111).ToList();
|
||||
|
||||
|
||||
//模糊查询
|
||||
var list3 = db.Queryable<MyTable02>().Where(it => it.name.Contains("a")).ToList();
|
||||
|
||||
|
||||
//分页
|
||||
var list4 = db.Queryable<MyTable02>().Where(it => it.voltage == 111)
|
||||
.ToPageList(1,2);
|
||||
|
||||
//删除子表
|
||||
var ts = list.First().ts;
|
||||
var de = DateTime.Now.AddYears(-1);
|
||||
var count=db.Deleteable<MyTable02>().Where(it=>it.ts>de).ExecuteCommand();
|
||||
};
|
||||
}
|
||||
|
||||
public class MyTable02
|
||||
|
Loading…
Reference in New Issue
Block a user