Skip to content

Commit

Permalink
Integrate comments by @smitpatel into source
Browse files Browse the repository at this point in the history
  • Loading branch information
roji committed Dec 27, 2019
1 parent 6ff8377 commit b3683fa
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal
{
public partial class NavigationExpandingExpressionVisitor
{
/// <summary>
/// Expands navigations in the given tree for given source.
/// Optionally also expands navigations for includes.
/// </summary>
private class ExpandingExpressionVisitor : ExpressionVisitor
{
private readonly NavigationExpandingExpressionVisitor _navigationExpandingExpressionVisitor;
Expand All @@ -28,6 +32,12 @@ public ExpandingExpressionVisitor(
_source = source;
}

/// <summary>
/// Expands navigations in the given tree for given source.
/// Optionally also expands navigations for includes.
/// </summary>
/// <param name="expression"> The query expression tree. </param>
/// <param name="applyIncludes"> Whether to also expand navigations for includes. </param>
public Expression Expand(Expression expression, bool applyIncludes = false)
{
expression = Visit(expression);
Expand Down Expand Up @@ -301,6 +311,10 @@ protected Expression ExpandNavigation(
}
}

/// <summary>
/// Expands an include tree. This is separate and needed because we may need to reconstruct parts of
/// <see cref="NewExpression"/> to apply includes.
/// </summary>
private sealed class IncludeExpandingExpressionVisitor : ExpandingExpressionVisitor
{
private readonly bool _isTracking;
Expand Down Expand Up @@ -502,6 +516,10 @@ private Expression ExpandIncludesHelper(Expression root, EntityReference entityR
}
}

/// <summary>
/// <see cref="NavigationExpansionExpression"/> remembers the pending selector so we don't expand
/// navigations unless we need to. This visitor applies them when we need to.
/// </summary>
private sealed class PendingSelectorExpandingExpressionVisitor : ExpressionVisitor
{
private readonly NavigationExpandingExpressionVisitor _visitor;
Expand Down Expand Up @@ -534,6 +552,9 @@ public override Expression Visit(Expression expression)
}
}

/// <summary>
/// Removes custom expressions from tree and converts it to LINQ again.
/// </summary>
private sealed class ReducingExpressionVisitor : ExpressionVisitor
{
public override Expression Visit(Expression expression)
Expand Down Expand Up @@ -596,6 +617,11 @@ public override Expression Visit(Expression expression)
}
}

/// <summary>
/// Marks <see cref="EntityReference"/> as nullable when coming from a left join.
/// Nullability is required to figure out if the navigation from this entity should be a left join or
/// an inner join.
/// </summary>
private sealed class EntityReferenceOptionalMarkingExpressionVisitor : ExpressionVisitor
{
public override Expression Visit(Expression expression)
Expand All @@ -611,6 +637,9 @@ public override Expression Visit(Expression expression)
}
}

/// <summary>
/// Allows self reference of query root inside query filters/defining queries.
/// </summary>
private sealed class SelfReferenceEntityQueryableRewritingExpressionVisitor : ExpressionVisitor
{
private readonly NavigationExpandingExpressionVisitor _navigationExpandingExpressionVisitor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public virtual void Print(ExpressionPrinter expressionPrinter)
}
}

/// <summary>
/// A tree structure of includes for a given entity type in <see cref="EntityReference"/>.
/// </summary>
protected class IncludeTreeNode : Dictionary<INavigation, IncludeTreeNode>
{
private EntityReference _entityReference;
Expand Down Expand Up @@ -162,6 +165,10 @@ private bool Equals(IncludeTreeNode includeTreeNode)
public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), EntityType);
}

/// <summary>
/// Stores information about the current queryable, its source, structure of projection, parameter type etc.
/// This is needed because once navigations are expanded we still remember these to avoid expanding again.
/// </summary>
protected class NavigationExpansionExpression : Expression, IPrintableExpression
{
private readonly List<(MethodInfo OrderingMethod, Expression KeySelector)> _pendingOrderings
Expand Down Expand Up @@ -250,6 +257,11 @@ public virtual void Print(ExpressionPrinter expressionPrinter)
}
}

/// <summary>
/// A leaf node on navigation tree, representing projection structures of
/// <see cref="NavigationExpansionExpression"/>. Contains <see cref="NavigationTreeExpression.Value"/>,
/// which can be <see cref="NewExpression"/> or <see cref="EntityReference"/>.
/// </summary>
protected class NavigationTreeExpression : NavigationTreeNode, IPrintableExpression
{
public NavigationTreeExpression(Expression value)
Expand All @@ -258,6 +270,9 @@ public NavigationTreeExpression(Expression value)
Value = value;
}

/// <summary>
/// Either <see cref="NewExpression"/> or <see cref="EntityReference"/>.
/// </summary>
public virtual Expression Value { get; private set; }

protected override Expression VisitChildren(ExpressionVisitor visitor)
Expand Down Expand Up @@ -287,6 +302,11 @@ public virtual void Print(ExpressionPrinter expressionPrinter)
}
}

/// <summary>
/// A node in navigation binary tree. A navigation tree is a structure of the current parameter, which
/// would be transparent identifier (hence it's a binary structure). This allows us to easily condense to
/// inner/outer member access.
/// </summary>
protected class NavigationTreeNode : Expression
{
private NavigationTreeNode _parent;
Expand Down Expand Up @@ -338,6 +358,10 @@ public virtual Expression GetExpression()
}
}

/// <summary>
/// Owned navigations are not expanded, since they map differently in different providers.
/// This remembers such references so that they can still be treated like navigations.
/// </summary>
protected class OwnedNavigationReference : Expression
{
public OwnedNavigationReference(Expression parent, INavigation navigation, EntityReference entityReference)
Expand Down

0 comments on commit b3683fa

Please sign in to comment.