mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-23 20:43:46 +08:00
Update demo
This commit is contained in:
@@ -24,75 +24,7 @@ namespace OrmTest
|
||||
ConfiQuery();
|
||||
}
|
||||
|
||||
private static void ConfiQuery()
|
||||
{
|
||||
var db = GetInstance();
|
||||
List<DataDictionary> datas = new List<DataDictionary>();
|
||||
datas.Add(new DataDictionary() { Code="1", Name="男",Type="sex" });
|
||||
datas.Add(new DataDictionary() { Code = "2", Name = "女", Type = "sex" });
|
||||
datas.Add(new DataDictionary() { Code = "1", Name = "南通市", Type = "city" });
|
||||
datas.Add(new DataDictionary() { Code = "2", Name = "苏州市", Type = "city" });
|
||||
datas.Add(new DataDictionary() { Code = "1", Name = "江苏省", Type = "province" });
|
||||
datas.Add(new DataDictionary() { Code = "2", Name = "湖南省", Type = "province" });
|
||||
db.CodeFirst.InitTables<DataDictionary>();
|
||||
db.CodeFirst.InitTables<Person>();
|
||||
db.DbMaintenance.TruncateTable<DataDictionary>();
|
||||
db.Insertable(datas).ExecuteCommand();
|
||||
|
||||
if (!db.ConfigQuery.Any())
|
||||
{
|
||||
var types= db.Queryable<DataDictionary>().Select(it => it.Type).Distinct().ToList();
|
||||
foreach (var type in types)
|
||||
{
|
||||
db.ConfigQuery.SetTable<DataDictionary>(it => it.Code, it => it.Name, type, it => it.Type == type);
|
||||
}
|
||||
|
||||
db.ConfigQuery.SetTable<Order>(it => it.Id, it => it.Name, "01", it => it.Id > 1);
|
||||
db.ConfigQuery.SetTable<Order>(it => it.Id, it => it.Name, "02", it => it.Id > 2);
|
||||
db.ConfigQuery.SetTable<Order>(it => it.Id, it => it.Name, null);
|
||||
}
|
||||
|
||||
|
||||
var res=db.Queryable<Person>().Select(it => new Person()
|
||||
{
|
||||
Id=it.Id.SelectAll(),
|
||||
SexName=it.SexId.GetConfigValue<DataDictionary>("sex"),
|
||||
ProviceName = it.SexId.GetConfigValue<DataDictionary>("province"),
|
||||
CityName = it.SexId.GetConfigValue<DataDictionary>("city"),
|
||||
}).ToList();//也支持支持写在Where或者Orderby
|
||||
|
||||
var list = db.Queryable<OrderItem>().Select(it => new OrderItem
|
||||
{
|
||||
ItemId = it.ItemId.SelectAll(),
|
||||
OrderName = it.OrderId.GetConfigValue<Order>("01")
|
||||
}).ToList();
|
||||
var list2 = db.Queryable<OrderItem>().Select(it => new OrderItem
|
||||
{
|
||||
ItemId = it.ItemId.SelectAll(),
|
||||
OrderName = it.OrderId.GetConfigValue<Order>("02")
|
||||
}).ToList();
|
||||
var list3 = db.Queryable<OrderItem>().Select(it => new OrderItem
|
||||
{
|
||||
ItemId = it.ItemId.SelectAll(),
|
||||
OrderName = it.OrderId.GetConfigValue<Order>()
|
||||
}).ToList();
|
||||
|
||||
var list4 = db.Queryable<OrderItem>().Select(it => new OrderItem
|
||||
{
|
||||
ItemId = it.ItemId.SelectAll(),
|
||||
OrderName = it.OrderId.GetConfigValue<Order>()
|
||||
})
|
||||
.Where(it=>it.OrderId.GetConfigValue<Order>()== "order1")
|
||||
.OrderBy(it=>it.OrderId.GetConfigValue<Order>()).ToList();
|
||||
|
||||
var list5 = db.Queryable<Order, OrderItem>((o, i) => o.Id == i.OrderId)
|
||||
.OrderBy((o,i)=>i.OrderId.GetConfigValue<Order>(),OrderByType.Desc)
|
||||
.Select<ViewOrder>((o,i)=>new ViewOrder() {
|
||||
Id= o.Id.SelectAll(),
|
||||
Name=i.OrderId.GetConfigValue<Order>()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private static void EasyExamples()
|
||||
{
|
||||
@@ -582,6 +514,77 @@ namespace OrmTest
|
||||
Console.WriteLine("#### Async End ####");
|
||||
}
|
||||
|
||||
|
||||
private static void ConfiQuery()
|
||||
{
|
||||
var db = GetInstance();
|
||||
List<DataDictionary> datas = new List<DataDictionary>();
|
||||
datas.Add(new DataDictionary() { Code = "1", Name = "男", Type = "sex" });
|
||||
datas.Add(new DataDictionary() { Code = "2", Name = "女", Type = "sex" });
|
||||
datas.Add(new DataDictionary() { Code = "1", Name = "南通市", Type = "city" });
|
||||
datas.Add(new DataDictionary() { Code = "2", Name = "苏州市", Type = "city" });
|
||||
datas.Add(new DataDictionary() { Code = "1", Name = "江苏省", Type = "province" });
|
||||
datas.Add(new DataDictionary() { Code = "2", Name = "湖南省", Type = "province" });
|
||||
db.CodeFirst.InitTables<DataDictionary>();
|
||||
db.CodeFirst.InitTables<Person>();
|
||||
db.DbMaintenance.TruncateTable<DataDictionary>();
|
||||
db.Insertable(datas).ExecuteCommand();
|
||||
|
||||
if (!db.ConfigQuery.Any())
|
||||
{
|
||||
var types = db.Queryable<DataDictionary>().Select(it => it.Type).Distinct().ToList();
|
||||
foreach (var type in types)
|
||||
{
|
||||
db.ConfigQuery.SetTable<DataDictionary>(it => it.Code, it => it.Name, type, it => it.Type == type);
|
||||
}
|
||||
|
||||
db.ConfigQuery.SetTable<Order>(it => it.Id, it => it.Name, "01", it => it.Id > 1);
|
||||
db.ConfigQuery.SetTable<Order>(it => it.Id, it => it.Name, "02", it => it.Id > 2);
|
||||
db.ConfigQuery.SetTable<Order>(it => it.Id, it => it.Name, null);
|
||||
}
|
||||
|
||||
|
||||
var res = db.Queryable<Person>().Select(it => new Person()
|
||||
{
|
||||
Id = it.Id.SelectAll(),
|
||||
SexName = it.SexId.GetConfigValue<DataDictionary>("sex"),
|
||||
ProviceName = it.SexId.GetConfigValue<DataDictionary>("province"),
|
||||
CityName = it.SexId.GetConfigValue<DataDictionary>("city"),
|
||||
}).ToList();//也支持支持写在Where或者Orderby
|
||||
|
||||
var list = db.Queryable<OrderItem>().Select(it => new OrderItem
|
||||
{
|
||||
ItemId = it.ItemId.SelectAll(),
|
||||
OrderName = it.OrderId.GetConfigValue<Order>("01")
|
||||
}).ToList();
|
||||
var list2 = db.Queryable<OrderItem>().Select(it => new OrderItem
|
||||
{
|
||||
ItemId = it.ItemId.SelectAll(),
|
||||
OrderName = it.OrderId.GetConfigValue<Order>("02")
|
||||
}).ToList();
|
||||
var list3 = db.Queryable<OrderItem>().Select(it => new OrderItem
|
||||
{
|
||||
ItemId = it.ItemId.SelectAll(),
|
||||
OrderName = it.OrderId.GetConfigValue<Order>()
|
||||
}).ToList();
|
||||
|
||||
var list4 = db.Queryable<OrderItem>().Select(it => new OrderItem
|
||||
{
|
||||
ItemId = it.ItemId.SelectAll(),
|
||||
OrderName = it.OrderId.GetConfigValue<Order>()
|
||||
})
|
||||
.Where(it => it.OrderId.GetConfigValue<Order>() == "order1")
|
||||
.OrderBy(it => it.OrderId.GetConfigValue<Order>()).ToList();
|
||||
|
||||
var list5 = db.Queryable<Order, OrderItem>((o, i) => o.Id == i.OrderId)
|
||||
.OrderBy((o, i) => i.OrderId.GetConfigValue<Order>(), OrderByType.Desc)
|
||||
.Select<ViewOrder>((o, i) => new ViewOrder()
|
||||
{
|
||||
Id = o.Id.SelectAll(),
|
||||
Name = i.OrderId.GetConfigValue<Order>()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
private static SqlSugarClient GetInstance()
|
||||
{
|
||||
return new SqlSugarClient(new ConnectionConfig()
|
||||
|
Reference in New Issue
Block a user