Update Query.Tree()

This commit is contained in:
sunkaixuan 2023-04-26 16:47:31 +08:00
parent 7d1a364c0b
commit db048c5aba
2 changed files with 4 additions and 4 deletions

View File

@ -335,12 +335,12 @@ namespace SqlSugar
var entity = this.Context.EntityMaintenance.GetEntityInfo<T>(); var entity = this.Context.EntityMaintenance.GetEntityInfo<T>();
var pk = GetTreeKey(entity); var pk = GetTreeKey(entity);
var list = this.ToList(); var list = this.ToList();
return GetTreeRoot(childListExpression, parentIdExpression, pk, list, rootValue); return GetTreeRoot(childListExpression, parentIdExpression, pk, list, rootValue)??new List<T>();
} }
public List<T> ToTree(Expression<Func<T, IEnumerable<object>>> childListExpression, Expression<Func<T, object>> parentIdExpression, object rootValue, object[] childIds) public List<T> ToTree(Expression<Func<T, IEnumerable<object>>> childListExpression, Expression<Func<T, object>> parentIdExpression, object rootValue, object[] childIds)
{ {
var list = this.ToList(); var list = this.ToList();
return TreeAndFilterIds(childListExpression, parentIdExpression, rootValue, childIds, ref list); return TreeAndFilterIds(childListExpression, parentIdExpression, rootValue, childIds, ref list) ?? new List<T>();
} }
public virtual DataTable ToDataTable() public virtual DataTable ToDataTable()

View File

@ -565,14 +565,14 @@ ParameterT parameter)
public async Task<List<T>> ToTreeAsync(Expression<Func<T, IEnumerable<object>>> childListExpression, Expression<Func<T, object>> parentIdExpression, object rootValue, object[] childIds) public async Task<List<T>> ToTreeAsync(Expression<Func<T, IEnumerable<object>>> childListExpression, Expression<Func<T, object>> parentIdExpression, object rootValue, object[] childIds)
{ {
var list = await this.ToListAsync(); var list = await this.ToListAsync();
return TreeAndFilterIds(childListExpression, parentIdExpression, rootValue, childIds, ref list); return TreeAndFilterIds(childListExpression, parentIdExpression, rootValue, childIds, ref list) ?? new List<T>();
} }
public async Task<List<T>> ToTreeAsync(Expression<Func<T, IEnumerable<object>>> childListExpression, Expression<Func<T, object>> parentIdExpression, object rootValue) public async Task<List<T>> ToTreeAsync(Expression<Func<T, IEnumerable<object>>> childListExpression, Expression<Func<T, object>> parentIdExpression, object rootValue)
{ {
var entity = this.Context.EntityMaintenance.GetEntityInfo<T>(); var entity = this.Context.EntityMaintenance.GetEntityInfo<T>();
var pk = GetTreeKey(entity); ; var pk = GetTreeKey(entity); ;
var list = await this.ToListAsync(); var list = await this.ToListAsync();
return GetTreeRoot(childListExpression, parentIdExpression, pk, list, rootValue); return GetTreeRoot(childListExpression, parentIdExpression, pk, list, rootValue) ?? new List<T>();
} }
public async Task<List<T>> ToParentListAsync(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue) public async Task<List<T>> ToParentListAsync(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue)
{ {