Browse Source

Add ToChildList by ids

pull/40/head
sunkaixuan 1 year ago
parent
commit
f35adcb829
  1. 13
      Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableExecuteSql.cs
  2. 13
      Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableExecuteSqlAsync.cs
  3. 2
      Src/Asp.NetCore2/SqlSugar/Interface/IQueryable.cs

13
Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableExecuteSql.cs

@ -244,7 +244,18 @@ namespace SqlSugar
var list = this.ToList();
return GetChildList(parentIdExpression, pk, list, primaryKeyValue, isContainOneself);
}
public List<T> ToChildList(Expression<Func<T, object>> parentIdExpression, object [] primaryKeyValues, bool isContainOneself = true)
{
var entity = this.Context.EntityMaintenance.GetEntityInfo<T>();
var pk = GetTreeKey(entity);
var list = this.ToList();
List<T> result = new List<T>();
foreach (var item in primaryKeyValues)
{
result.AddRange(GetChildList(parentIdExpression, pk, list, item, isContainOneself));
}
return result;
}
public List<T> ToParentList(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue)
{
var entity = this.Context.EntityMaintenance.GetEntityInfo<T>();

13
Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableExecuteSqlAsync.cs

@ -675,7 +675,18 @@ ParameterT parameter)
return GetChildList(parentIdExpression, pk, list, primaryKeyValue, isContainOneself);
}
public async Task<List<T>> ToChildListAsync(Expression<Func<T, object>> parentIdExpression, object[] primaryKeyValues, bool isContainOneself = true)
{
var entity = this.Context.EntityMaintenance.GetEntityInfo<T>();
var pk = GetTreeKey(entity);
var list =await this.ToListAsync();
List<T> result = new List<T>();
foreach (var item in primaryKeyValues)
{
result.AddRange(GetChildList(parentIdExpression, pk, list, item, isContainOneself));
}
return result;
}
public Task<int> IntoTableAsync<TableEntityType>(CancellationToken cancellationToken = default)
{
return IntoTableAsync(typeof(TableEntityType), cancellationToken);

2
Src/Asp.NetCore2/SqlSugar/Interface/IQueryable.cs

@ -220,7 +220,9 @@ namespace SqlSugar
KeyValuePair<string, List<SugarParameter>> ToSql();
string ToSqlString();
List<T> ToChildList(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue, bool isContainOneself = true);
List<T> ToChildList(Expression<Func<T, object>> parentIdExpression, object[] primaryKeyValues, bool isContainOneself = true);
Task<List<T>> ToChildListAsync(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue, bool isContainOneself = true);
Task<List<T>> ToChildListAsync(Expression<Func<T, object>> parentIdExpression, object[] primaryKeyValues, bool isContainOneself = true);
List<T> ToParentList(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue);
List<T> ToParentList(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue, Expression<Func<T, bool>> parentWhereExpression);

Loading…
Cancel
Save