- 优化 IncludeMany 筛选字段中未指定主键,并且 then.IncludeMany 继续向下,则自动附加查询主键;

This commit is contained in:
28810
2020-09-28 21:03:38 +08:00
parent e22c2617c4
commit 31775bee25
4 changed files with 206 additions and 167 deletions

View File

@ -806,6 +806,15 @@ namespace FreeSql.Internal.CommonProvider
var tmpMemberInfo = tbrefCol.Table.Properties[tbrefCol.CsName];
newinitExpBindings.Add(Expression.Bind(tmpMemberInfo, Expression.MakeMemberAccess(selectExp.Parameters[0], tmpMemberInfo)));
}
if (subSelect._includeToList.Any()) //如果还有向下 IncludeMany要把它的主键也查出来
{
foreach (var tbrefPkCol in _commonUtils.GetTableByEntity(tbref.RefEntityType).Primarys)
{
if (newinitExpBindings.Any(a => a.Member.Name == tbrefPkCol.CsName)) continue;
var tmpMemberInfo = tbrefPkCol.Table.Properties[tbrefPkCol.CsName];
newinitExpBindings.Add(Expression.Bind(tmpMemberInfo, Expression.MakeMemberAccess(selectExp.Parameters[0], tmpMemberInfo)));
}
}
Expression newinitExp = Expression.MemberInit(tmpinitExp.NewExpression, newinitExpBindings.ToList());
var selectExpParam = subSelect._tables[0].Parameter ?? Expression.Parameter(typeof(TNavigate), subSelectT1Alias);
newinitExp = new NewExpressionVisitor(selectExpParam, selectExp.Parameters[0]).Replace(newinitExp);