mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-05 17:37:58 +08:00
Update ToChildList
This commit is contained in:
parent
8c187165ae
commit
0638af8cdc
@ -1358,19 +1358,45 @@ namespace SqlSugar
|
||||
var list= this.ToPivotList(columnSelector, rowSelector, dataSelector);
|
||||
return this.Context.Utilities.SerializeObject(list);
|
||||
}
|
||||
public List<T> ToChildList(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue)
|
||||
public List<T> ToChildList(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue,bool isContainOneself = true)
|
||||
{
|
||||
var entity = this.Context.EntityMaintenance.GetEntityInfo<T>();
|
||||
var pk = GetTreeKey(entity);
|
||||
var list = this.ToList();
|
||||
return GetChildList(parentIdExpression, pk, list, primaryKeyValue);
|
||||
if (isContainOneself)
|
||||
{
|
||||
var result= GetChildList(parentIdExpression, pk, list, primaryKeyValue);
|
||||
var addItem = this.Context.Queryable<T>().In(pk, primaryKeyValue).First();
|
||||
if (addItem != null)
|
||||
{
|
||||
result.Add(addItem);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetChildList(parentIdExpression, pk, list, primaryKeyValue);
|
||||
}
|
||||
}
|
||||
public async Task<List<T>> ToChildListAsync(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue)
|
||||
public async Task<List<T>> ToChildListAsync(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue,bool isContainOneself=true)
|
||||
{
|
||||
var entity = this.Context.EntityMaintenance.GetEntityInfo<T>();
|
||||
var pk = GetTreeKey(entity);
|
||||
var list = await this.ToListAsync();
|
||||
return GetChildList(parentIdExpression,pk,list, primaryKeyValue);
|
||||
if (isContainOneself)
|
||||
{
|
||||
var result = GetChildList(parentIdExpression, pk, list, primaryKeyValue);
|
||||
var addItem = this.Context.Queryable<T>().In(pk, primaryKeyValue).First();
|
||||
if (addItem != null)
|
||||
{
|
||||
result.Add(addItem);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetChildList(parentIdExpression, pk, list, primaryKeyValue);
|
||||
}
|
||||
}
|
||||
public List<T> ToParentList(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue)
|
||||
{
|
||||
|
@ -172,8 +172,8 @@ namespace SqlSugar
|
||||
Task<string> ToJsonPageAsync(int pageIndex, int pageSize, RefAsync<int> totalNumber);
|
||||
KeyValuePair<string, List<SugarParameter>> ToSql();
|
||||
string ToSqlString();
|
||||
List<T> ToChildList(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue);
|
||||
Task<List<T>> ToChildListAsync(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue);
|
||||
List<T> ToChildList(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue, bool isContainOneself = true);
|
||||
Task<List<T>> ToChildListAsync(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue, bool isContainOneself = true);
|
||||
List<T> ToParentList(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue);
|
||||
Task<List<T>> ToParentListAsync(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue);
|
||||
List<T> ToTree(Expression<Func<T,IEnumerable<object>>> childListExpression, Expression<Func<T,object>> parentIdExpression,object rootValue);
|
||||
|
Loading…
Reference in New Issue
Block a user