Browse Source

Update ToParentList bug

pull/5/MERGE
sunkaixuna 3 years ago
parent
commit
7fe10faaf6
  1. 6
      Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

6
Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

@ -958,16 +958,16 @@ namespace SqlSugar
var parentIdName =UtilConvert.ToMemberExpression((parentIdExpression as LambdaExpression).Body).Member.Name; var parentIdName =UtilConvert.ToMemberExpression((parentIdExpression as LambdaExpression).Body).Member.Name;
var ParentInfo = entity.Columns.First(it => it.PropertyName == parentIdName); var ParentInfo = entity.Columns.First(it => it.PropertyName == parentIdName);
var parentPropertyName= ParentInfo.DbColumnName; var parentPropertyName= ParentInfo.DbColumnName;
var current = this.Context.Queryable<T>().InSingle(primaryKeyValue); var current = this.Context.Queryable<T>().AS(this.QueryBuilder.GetTableNameString).InSingle(primaryKeyValue);
if (current != null) if (current != null)
{ {
result.Add(current); result.Add(current);
object parentId = ParentInfo.PropertyInfo.GetValue(current,null); object parentId = ParentInfo.PropertyInfo.GetValue(current,null);
int i = 0; int i = 0;
while (parentId!=null&&this.Context.Queryable<T>().In(parentId).Any()) while (parentId!=null&&this.Context.Queryable<T>().AS(this.QueryBuilder.GetTableNameString).In(parentId).Any())
{ {
Check.Exception(i > 100, ErrorMessage.GetThrowMessage("Dead cycle", "出现死循环或超出循环上限(100),检查最顶层的ParentId是否是null或者0")); Check.Exception(i > 100, ErrorMessage.GetThrowMessage("Dead cycle", "出现死循环或超出循环上限(100),检查最顶层的ParentId是否是null或者0"));
var parent = this.Context.Queryable<T>().InSingle(parentId); var parent = this.Context.Queryable<T>().AS(this.QueryBuilder.GetTableNameString).InSingle(parentId);
result.Add(parent); result.Add(parent);
parentId= ParentInfo.PropertyInfo.GetValue(parent, null); parentId= ParentInfo.PropertyInfo.GetValue(parent, null);
++i; ++i;

Loading…
Cancel
Save