mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Update demo
This commit is contained in:
parent
a7150cf9c7
commit
644a67b58c
@ -27,6 +27,38 @@ namespace OrmTest
|
|||||||
private static void ConfiQuery()
|
private static void ConfiQuery()
|
||||||
{
|
{
|
||||||
var db = GetInstance();
|
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.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
db.DbMaintenance.TruncateTable("DataDictionary");
|
||||||
if (!db.ConfigQuery.Any())
|
if (!db.ConfigQuery.Any())
|
||||||
{
|
{
|
||||||
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, "01", it => it.Id > 1);
|
||||||
|
34
Src/Asp.Net/SqlServerTest/Models/DataDictionary.cs
Normal file
34
Src/Asp.Net/SqlServerTest/Models/DataDictionary.cs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OrmTest
|
||||||
|
{
|
||||||
|
public class DataDictionary
|
||||||
|
{
|
||||||
|
public string Code { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string Type { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Person
|
||||||
|
{
|
||||||
|
//数据库字段
|
||||||
|
[SqlSugar.SugarColumn(IsPrimaryKey =true,IsIdentity =true)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public int SexId { get; set; }
|
||||||
|
public int CityId { get; set; }
|
||||||
|
public int ProviceId { get; set; }
|
||||||
|
|
||||||
|
//非数据库字段
|
||||||
|
[SqlSugar.SugarColumn(IsIgnore =true)]
|
||||||
|
public string SexName { get; set; }
|
||||||
|
[SqlSugar.SugarColumn(IsIgnore = true)]
|
||||||
|
public string CityName { get; set; }
|
||||||
|
[SqlSugar.SugarColumn(IsIgnore = true)]
|
||||||
|
public string ProviceName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -68,6 +68,7 @@
|
|||||||
<Compile Include="Demo\DemoF_Utilities.cs" />
|
<Compile Include="Demo\DemoF_Utilities.cs" />
|
||||||
<Compile Include="Demo\DemoG_SimpleClient.cs" />
|
<Compile Include="Demo\DemoG_SimpleClient.cs" />
|
||||||
<Compile Include="Demo\DemoH_Tenant.cs" />
|
<Compile Include="Demo\DemoH_Tenant.cs" />
|
||||||
|
<Compile Include="Models\DataDictionary.cs" />
|
||||||
<Compile Include="Models\Custom.cs" />
|
<Compile Include="Models\Custom.cs" />
|
||||||
<Compile Include="Models\EntityMapper.cs" />
|
<Compile Include="Models\EntityMapper.cs" />
|
||||||
<Compile Include="Models\Mapper.cs" />
|
<Compile Include="Models\Mapper.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user