SqlSugar/Src/Asp.Net/SqlServerTest/UnitTest/UintDynamic.cs

72 lines
2.4 KiB
C#
Raw Normal View History

2022-04-29 18:50:58 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar;
namespace OrmTest
{
public class UintDynamic
{
public static void Init()
{
var db = NewUnitTest.Db;
var list=db.Queryable<StudentA>()
2022-04-29 20:58:12 +08:00
.Includes(it => it.Books.Where(z=>z.BookId==1)
.MappingField(z=>z.studenId,()=>it.StudentId)
2022-05-05 09:13:59 +08:00
.MappingField(z => z.BookId, () => it.StudentId).ToList()
, c=>c.bookChilds
.MappingField(z=>z.BookId,()=>c.BookId).ToList())
2022-04-29 18:50:58 +08:00
.ToList();
2022-05-03 13:46:54 +08:00
var list2 = db.Queryable<StudentA>().ToList();
db.ThenMapper(list2, it =>
{
it.Books = db.Queryable<BookA>().Where(z=>z.BookId==1).SetContext(
z => z.studenId, () => it.StudentId,
z => z.BookId, () => it.StudentId,
it);
});
2022-05-06 12:36:27 +08:00
var list3 = db.Queryable<StudentA>()
.Includes(it => it.SchoolA.MappingField(z=>z.SchoolId,()=>it.SchoolId).ToList() )
.ToList();
2022-04-29 18:50:58 +08:00
}
public class StudentA
{
[SugarColumn(IsPrimaryKey = true)]
public int StudentId { get; set; }
public string Name { get; set; }
[SugarColumn(IsNullable = true)]
public int? SchoolId { get; set; }
[Navigate(NavigateType.Dynamic,null)]
public SchoolA SchoolA { get; set; }
[Navigate(NavigateType.Dynamic, null)]
public List<BookA> Books { get; set; }
}
public class SchoolA
{
[SugarColumn(IsPrimaryKey = true)]
public int SchoolId { get; set; }
[SugarColumn(ColumnName = "SchoolName")]
public string School_Name { get; set; }
}
public class BookA
{
[SugarColumn(IsPrimaryKey = true)]
public int BookId { get; set; }
[SugarColumn(ColumnName = "Name")]
public string Names { get; set; }
public int studenId { get; set; }
2022-05-05 09:13:59 +08:00
[Navigate(NavigateType.Dynamic,null)]
public List<BookA> bookChilds { get; set; }
2022-04-29 18:50:58 +08:00
}
}
}