mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-25 01:14:33 +08:00
async Queryable.Mapper bug
This commit is contained in:
parent
3a03456593
commit
326cffa0bc
@ -12,51 +12,16 @@ namespace OrmTest.Demo
|
|||||||
{
|
{
|
||||||
var db = GetInstance();
|
var db = GetInstance();
|
||||||
|
|
||||||
//auto fill ViewModelStudent3
|
|
||||||
var s11 = db.Queryable<Student, School>((st, sc) => st.SchoolId == sc.Id)
|
|
||||||
.Select<ViewModelStudent3>().ToList();
|
|
||||||
|
|
||||||
|
var x = db.Queryable<Student>()
|
||||||
var s12 = db.Queryable<Student, School>((st, sc) => st.SchoolId == sc.Id).Select<ViewModelStudent3>()
|
|
||||||
|
|
||||||
.Mapper((it, cache) =>
|
.Mapper((it, cache) =>
|
||||||
{
|
{
|
||||||
|
|
||||||
var allSchools = cache.GetListByPrimaryKeys<School>(vmodel => vmodel.SchoolId);
|
it.Name = "xx";
|
||||||
//sql select shool where id (in(ViewModelStudent3[0].SchoolId , ViewModelStudent3[1].SchoolId...)
|
}).ToListAsync();
|
||||||
|
|
||||||
//Equal to allSchools
|
x .Wait();
|
||||||
//var allSchools2= cache.Get(list =>
|
|
||||||
// {
|
|
||||||
// var ids=list.Select(i => it.SchoolId).ToList();
|
|
||||||
// return db.Queryable<School>().In(ids).ToList();
|
|
||||||
//});Complex writing metho
|
|
||||||
|
|
||||||
|
|
||||||
/*one to one*/
|
|
||||||
//Good performance
|
|
||||||
it.School = allSchools.FirstOrDefault(i => i.Id == it.SchoolId);
|
|
||||||
|
|
||||||
//Poor performance.
|
|
||||||
//it.School = db.Queryable<School>().InSingle(it.SchoolId);
|
|
||||||
|
|
||||||
|
|
||||||
/*one to many*/
|
|
||||||
it.Schools = allSchools.Where(i => i.Id == it.SchoolId).ToList();
|
|
||||||
|
|
||||||
|
|
||||||
/*C# syntax conversion*/
|
|
||||||
it.Name = it.Name == null ? "null" : it.Name;
|
|
||||||
|
|
||||||
}).ToList();
|
|
||||||
|
|
||||||
|
|
||||||
var s13 = db.Queryable<Student, School>((st, sc) => st.SchoolId == sc.Id).Select<ViewModelStudent3>()
|
|
||||||
|
|
||||||
.Mapper((it, cache) =>
|
|
||||||
{
|
|
||||||
it.Schools = db.Queryable<School>().Where(i => i.Id == it.SchoolId).ToList();
|
|
||||||
}).ToList();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1298,6 +1298,10 @@ namespace SqlSugar
|
|||||||
var asyncContext = this.Context.Utilities.CopyContext(true);
|
var asyncContext = this.Context.Utilities.CopyContext(true);
|
||||||
asyncContext.CurrentConnectionConfig.IsAutoCloseConnection = true;
|
asyncContext.CurrentConnectionConfig.IsAutoCloseConnection = true;
|
||||||
var asyncQueryable = asyncContext.Queryable<ExpandoObject>().Select<T>(string.Empty).WithCacheIF(IsCache, CacheTime);
|
var asyncQueryable = asyncContext.Queryable<ExpandoObject>().Select<T>(string.Empty).WithCacheIF(IsCache, CacheTime);
|
||||||
|
if (this.MapperAction != null)
|
||||||
|
asyncQueryable.Mapper(MapperAction);
|
||||||
|
if (this.MapperActionWithCache != null)
|
||||||
|
asyncQueryable.Mapper(MapperActionWithCache);
|
||||||
CopyQueryBuilder(asyncQueryable.QueryBuilder); return asyncQueryable;
|
CopyQueryBuilder(asyncQueryable.QueryBuilder); return asyncQueryable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user