Update demo

This commit is contained in:
sunkaixuan
2022-04-21 17:20:33 +08:00
parent c3d6483efa
commit c3b7a169c8
2 changed files with 8 additions and 3 deletions

View File

@@ -81,9 +81,10 @@ namespace OrmTest
db.ThenMapper(list.Select(it => it.SchoolA), sch => db.ThenMapper(list.Select(it => it.SchoolA), sch =>
{ {
//参数1: room表关联字段 参数2: school表关联字段 参数3: school当前记录 //参数1: room表关联字段 参数2: school表关联字段 参数3: school当前记录
sch.RoomList = db.Queryable<RoomA>().SetContext(room => room.SchoolId, () => sch.SchoolId, sch).ToList(); if(sch!=null)
sch.RoomList = db.Queryable<RoomA>().SetContext(room => room.SchoolId, () => sch.SchoolId, sch).ToList();
sch.TeacherList = db.Queryable<TeacherA>().SetContext(teachera => teachera.SchoolId, () => sch.SchoolId, sch).ToList(); if (sch != null)
sch.TeacherList = db.Queryable<TeacherA>().SetContext(teachera => teachera.SchoolId, () => sch.SchoolId, sch).ToList();
}); });

View File

@@ -1332,6 +1332,10 @@ namespace SqlSugar
} }
public List<T> SetContext<ParameterT>(Expression<Func<T, object>> thisFiled, Expression<Func<object>> mappingFiled, ParameterT parameter) public List<T> SetContext<ParameterT>(Expression<Func<T, object>> thisFiled, Expression<Func<object>> mappingFiled, ParameterT parameter)
{ {
if (parameter == null)
{
return new List<T>();
}
List<T> result = new List<T>(); List<T> result = new List<T>();
var entity = this.Context.EntityMaintenance.GetEntityInfo<ParameterT>(); var entity = this.Context.EntityMaintenance.GetEntityInfo<ParameterT>();
var queryableContext = this.Context.TempItems["Queryable_To_Context"] as MapperContext<ParameterT>; var queryableContext = this.Context.TempItems["Queryable_To_Context"] as MapperContext<ParameterT>;