Browse Source

Navigate query support skip take

pull/19/head
sunkaixuan 3 years ago
parent
commit
e9ce346e63
  1. 4
      Src/Asp.Net/SqlServerTest/UnitTest/UCustom012.cs
  2. 16
      Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/NavigatManager.cs

4
Src/Asp.Net/SqlServerTest/UnitTest/UCustom012.cs

@ -108,6 +108,10 @@ namespace OrmTest
var list3_1 = db.Queryable<StudentA>()
.Includes(x => x.Books.MappingField(z=>z.Names,()=>x.Name).ToList())
.ToList();
var list3_11 = db.Queryable<StudentA>()
.Includes(x => x.Books.Skip(1).Take(2).ToList())
.ToList();
//先用Mapper导航映射查出第二层

16
Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/NavigatManager.cs

@ -336,21 +336,31 @@ namespace SqlSugar
}).GroupBy(it => it.l).ToList();
foreach (var item in groupQuery)
{
var itemSelectList=item.Select(it => it.n);
if (sqlObj.Skip != null)
{
itemSelectList = itemSelectList
.Skip(sqlObj.Skip.Value);
}
if (sqlObj.Take != null)
{
itemSelectList = itemSelectList
.Take(sqlObj.Take.Value);
}
if (sqlObj.MappingExpressions.HasValue())
{
MappingFieldsHelper<T> helper = new MappingFieldsHelper<T>();
helper.NavEntity = navEntityInfo;
helper.Context = this.Context;
helper.RootEntity = this.Context.EntityMaintenance.GetEntityInfo<T>();
helper.SetChildList(navObjectNameColumnInfo, item.Key, item.Select(it => it.n).ToList(), sqlObj.MappingExpressions);
helper.SetChildList(navObjectNameColumnInfo, item.Key, itemSelectList.ToList(), sqlObj.MappingExpressions);
}
else
{
var instance = Activator.CreateInstance(navObjectNamePropety.PropertyType, true);
var ilist = instance as IList;
foreach (var value in item.Select(it => it.n).ToList())
foreach (var value in itemSelectList.ToList())
{
ilist.Add(value);
}

Loading…
Cancel
Save