forked from dotnet/efcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIncludeExpression.cs
More file actions
111 lines (95 loc) · 4.63 KB
/
Copy pathIncludeExpression.cs
File metadata and controls
111 lines (95 loc) · 4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// 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 JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Utilities;
#nullable enable
namespace Microsoft.EntityFrameworkCore.Query
{
/// <summary>
/// <para>
/// An expression that represents include operation in <see cref="ShapedQueryExpression.ShaperExpression" />.
/// </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 IncludeExpression : Expression, IPrintableExpression
{
/// <summary>
/// Creates a new instance of the <see cref="IncludeExpression" /> class.
/// </summary>
/// <param name="entityExpression"> An expression to get entity which is performing include. </param>
/// <param name="navigationExpression"> An expression to get included navigation element. </param>
/// <param name="navigation"> The navigation for this include operation. </param>
public IncludeExpression(
[NotNull] Expression entityExpression,
[NotNull] Expression navigationExpression,
[NotNull] INavigationBase navigation)
{
Check.NotNull(entityExpression, nameof(entityExpression));
Check.NotNull(navigationExpression, nameof(navigationExpression));
Check.NotNull(navigation, nameof(navigation));
EntityExpression = entityExpression;
NavigationExpression = navigationExpression;
Navigation = navigation;
Type = EntityExpression.Type;
}
/// <summary>
/// The expression representing entity perfoming this include.
/// </summary>
public virtual Expression EntityExpression { get; }
/// <summary>
/// The expression representing included navigation element.
/// </summary>
public virtual Expression NavigationExpression { get; }
/// <summary>
/// The navigation associated with this include operation.
/// </summary>
public virtual INavigationBase Navigation { get; }
/// <inheritdoc />
public sealed override ExpressionType NodeType
=> ExpressionType.Extension;
/// <inheritdoc />
public override Type Type { get; }
/// <inheritdoc />
protected override Expression VisitChildren(ExpressionVisitor visitor)
{
Check.NotNull(visitor, nameof(visitor));
var newEntityExpression = visitor.Visit(EntityExpression);
var newNavigationExpression = visitor.Visit(NavigationExpression);
return Update(newEntityExpression, newNavigationExpression);
}
/// <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="entityExpression"> The <see cref="EntityExpression" /> property of the result. </param>
/// <param name="navigationExpression"> The <see cref="NavigationExpression" /> property of the result. </param>
/// <returns> This expression if no children changed, or an expression with the updated children. </returns>
public virtual IncludeExpression Update([NotNull] Expression entityExpression, [NotNull] Expression navigationExpression)
{
Check.NotNull(entityExpression, nameof(entityExpression));
Check.NotNull(navigationExpression, nameof(navigationExpression));
return entityExpression != EntityExpression || navigationExpression != NavigationExpression
? new IncludeExpression(entityExpression, navigationExpression, Navigation)
: this;
}
/// <inheritdoc />
void IPrintableExpression.Print(ExpressionPrinter expressionPrinter)
{
Check.NotNull(expressionPrinter, nameof(expressionPrinter));
expressionPrinter.AppendLine("IncludeExpression(");
using (expressionPrinter.Indent())
{
expressionPrinter.Visit(EntityExpression);
expressionPrinter.AppendLine(", ");
expressionPrinter.Visit(NavigationExpression);
expressionPrinter.AppendLine($", {Navigation.Name})");
}
}
}
}