Add Complex Model Demo

This commit is contained in:
sunkaixuan
2017-06-11 11:27:39 +08:00
parent 9c1ce55277
commit 2c5f8ba4a9
5 changed files with 70 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SqlSugar;
using OrmTest.Demo;
namespace OrmTest.Demo
{
public class ComplexModel : DemoBase
{
public static void Init()
{
var db = GetInstance();
var student = db.Queryable<CMStudent>().ToList();
}
}
[SugarTable("Student")]
public class CMStudent : ModelContext
{
public int Id { get; set; }
public string Name { get; set; }
public int SchoolId { get; set; }
[SugarColumn(IsIgnore = true)]
public CMSchool SchoolSingle
{
get
{
return base.CreateMapping<CMSchool>().Single(it => it.Id == this.Id);
}
}
[SugarColumn(IsIgnore = true)]
public List<CMSchool> SchoolList
{
get
{
return base.CreateMapping<CMSchool>().Where(it => it.Id == this.Id).ToList();
}
}
}
[SugarTable("School")]
public class CMSchool
{
public int Id { get; set; }
public string Name { get; set; }
}
}

View File

@@ -42,6 +42,7 @@ namespace OrmTest
OrmTest.Demo.JoinSql.Init(); OrmTest.Demo.JoinSql.Init();
OrmTest.Demo.Filter.Init(); OrmTest.Demo.Filter.Init();
OrmTest.Demo.MaterSlave.Init(); OrmTest.Demo.MaterSlave.Init();
OrmTest.Demo.ComplexModel.Init();
} }
} }
} }

View File

@@ -48,6 +48,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Config.cs" /> <Compile Include="Config.cs" />
<Compile Include="Demos\ComplexModel.cs" />
<Compile Include="Demos\Filter.cs" /> <Compile Include="Demos\Filter.cs" />
<Compile Include="Demos\JoinSql.cs" /> <Compile Include="Demos\JoinSql.cs" />
<Compile Include="Demos\DbFirst.cs" /> <Compile Include="Demos\DbFirst.cs" />

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SqlSugar
{
public class ModelContext
{
internal SqlSugarClient Context { get; set; }
public ISugarQueryable<T> CreateMapping<T>()where T:class,new()
{
return Context.Queryable<T>();
}
}
}

View File

@@ -64,6 +64,7 @@
<Compile Include="Abstract\InsertableProvider\InsertableProvider.cs" /> <Compile Include="Abstract\InsertableProvider\InsertableProvider.cs" />
<Compile Include="Abstract\DeleteProvider\DeleteableProvider.cs" /> <Compile Include="Abstract\DeleteProvider\DeleteableProvider.cs" />
<Compile Include="Abstract\UpdateProvider\UpdateableProvider.cs" /> <Compile Include="Abstract\UpdateProvider\UpdateableProvider.cs" />
<Compile Include="Entities\ModelContext.cs" />
<Compile Include="Entities\SchemaInfo.cs" /> <Compile Include="Entities\SchemaInfo.cs" />
<Compile Include="Entities\SqlFilter.cs" /> <Compile Include="Entities\SqlFilter.cs" />
<Compile Include="Enum\DbObjectType.cs" /> <Compile Include="Enum\DbObjectType.cs" />