You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
1.9 KiB
78 lines
1.9 KiB
8 years ago
|
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();
|
||
8 years ago
|
var students = db.Queryable<CMStudent>().ToList();
|
||
8 years ago
|
if (students != null)
|
||
|
{
|
||
|
foreach (var item in students)
|
||
|
{
|
||
|
Console.WriteLine(item.SchoolName);
|
||
|
if (item.SchoolSingle != null)
|
||
|
{
|
||
|
Console.WriteLine(item.SchoolSingle.Name);
|
||
|
}
|
||
|
if (item.SchoolList != null)
|
||
|
{
|
||
|
Console.WriteLine(item.SchoolList.Count);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
8 years ago
|
}
|
||
|
}
|
||
|
|
||
|
[SugarTable("Student")]
|
||
|
public class CMStudent : ModelContext
|
||
|
{
|
||
|
public int Id { get; set; }
|
||
|
public string Name { get; set; }
|
||
|
public int SchoolId { get; set; }
|
||
|
|
||
8 years ago
|
[SugarColumn(IsIgnore = true)]
|
||
|
public string SchoolName
|
||
|
{
|
||
|
get
|
||
|
{
|
||
|
if (this.SchoolSingle != null)
|
||
|
return this.SchoolSingle.Name;
|
||
|
else
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
[SugarColumn(IsIgnore = true)]
|
||
|
public CMSchool SchoolSingle
|
||
|
{
|
||
|
get
|
||
|
{
|
||
8 years ago
|
return base.CreateMapping<CMSchool>().Single(it => it.Id == this.SchoolId);
|
||
8 years ago
|
}
|
||
|
}
|
||
|
|
||
|
[SugarColumn(IsIgnore = true)]
|
||
|
public List<CMSchool> SchoolList
|
||
|
{
|
||
|
get
|
||
|
{
|
||
8 years ago
|
return base.CreateMapping<CMSchool>().Where(it => it.Id == this.SchoolId).ToList();
|
||
8 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
[SugarTable("School")]
|
||
|
public class CMSchool
|
||
|
{
|
||
|
public int Id { get; set; }
|
||
|
public string Name { get; set; }
|
||
|
}
|
||
|
}
|