Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query: Introduce client projections in SelectExpression #24675

Merged
1 commit merged into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions src/EFCore.Relational/Query/CollectionResultExpression.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore.Query
{
/// <summary>
/// <para>
/// An expression that represents creation of a collection in <see cref="ShapedQueryExpression.ShaperExpression" /> for relational providers.
/// </para>
/// <para>
/// This type is typically used by database providers (and other extensions). It is generally
/// not used in application code.
/// </para>
/// </summary>
public class CollectionResultExpression : Expression, IPrintableExpression
{
/// <summary>
/// Creates a new instance of the <see cref="CollectionResultExpression" /> class.
/// </summary>
/// <param name="projectionBindingExpression"> An expression reprensenting how to get the subquery from SelectExpression to get the elements. </param>
/// <param name="navigation"> A navigation associated with this collection, if any. </param>
/// <param name="elementType"> The clr type of individual elements in the collection. </param>
public CollectionResultExpression(
ProjectionBindingExpression projectionBindingExpression,
INavigationBase? navigation,
Type elementType)
{
ProjectionBindingExpression = projectionBindingExpression;
Navigation = navigation;
ElementType = elementType;
}

/// <summary>
/// The expression to get the subquery for this collection.
/// </summary>
public virtual ProjectionBindingExpression ProjectionBindingExpression { get; }
/// <summary>
/// The navigation if associated with the collection.
/// </summary>
public virtual INavigationBase? Navigation { get; }
/// <summary>
/// The clr type of elements of the collection.
/// </summary>
public virtual Type ElementType { get; }

/// <inheritdoc />
public override Type Type => ProjectionBindingExpression.Type;
/// <inheritdoc />
public override ExpressionType NodeType => ExpressionType.Extension;

/// <inheritdoc />
protected override Expression VisitChildren(ExpressionVisitor visitor)
{
Check.NotNull(visitor, nameof(visitor));

var projectionBindingExpression = (ProjectionBindingExpression)visitor.Visit(ProjectionBindingExpression);

return Update(projectionBindingExpression);
}

/// <summary>
/// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will
/// return this expression.
/// </summary>
/// <param name="projectionBindingExpression"> The <see cref="ProjectionBindingExpression" /> property of the result. </param>
/// <returns> This expression if no children changed, or an expression with the updated children. </returns>
public virtual CollectionResultExpression Update(ProjectionBindingExpression projectionBindingExpression)
{
Check.NotNull(projectionBindingExpression, nameof(projectionBindingExpression));

return projectionBindingExpression != ProjectionBindingExpression
? new CollectionResultExpression(projectionBindingExpression, Navigation, ElementType)
: this;
}

/// <inheritdoc />
public virtual void Print(ExpressionPrinter expressionPrinter)
{
expressionPrinter.AppendLine("CollectionResultExpression:");
using (expressionPrinter.Indent())
{
expressionPrinter.Append("ProjectionBindingExpression:");
expressionPrinter.Visit(ProjectionBindingExpression);
expressionPrinter.AppendLine();
if (Navigation != null)
{
expressionPrinter.Append("Navigation:").AppendLine(Navigation.ToString()!);
}
expressionPrinter.Append("ElementType:").AppendLine(ElementType.ShortDisplayName());
}
}
}
}
3 changes: 3 additions & 0 deletions src/EFCore.Relational/Query/EntityProjectionExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,8 @@ public virtual void AddNavigationBinding(INavigation navigation, EntityShaperExp
? expression
: null;
}

/// <inheritdoc />
public override string ToString() => $"EntityProjectionExpression: {EntityType.ShortName()}";
}
}

This file was deleted.

Loading