|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | + |
| 4 | +namespace Microsoft.EntityFrameworkCore.Query.Internal; |
| 5 | + |
| 6 | +/// <summary> |
| 7 | +/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to |
| 8 | +/// the same compatibility standards as public APIs. It may be changed or removed without notice in |
| 9 | +/// any release. You should only use it directly in your code with extreme caution and knowing that |
| 10 | +/// doing so can result in application failures when updating to a new Entity Framework Core release. |
| 11 | +/// </summary> |
| 12 | +public sealed class SqlQueryRootExpression : QueryRootExpression |
| 13 | +{ |
| 14 | + /// <summary> |
| 15 | + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to |
| 16 | + /// the same compatibility standards as public APIs. It may be changed or removed without notice in |
| 17 | + /// any release. You should only use it directly in your code with extreme caution and knowing that |
| 18 | + /// doing so can result in application failures when updating to a new Entity Framework Core release. |
| 19 | + /// </summary> |
| 20 | + public SqlQueryRootExpression( |
| 21 | + IAsyncQueryProvider queryProvider, |
| 22 | + Type elementType, |
| 23 | + string sql, |
| 24 | + Expression argument) |
| 25 | + : base(queryProvider, elementType) |
| 26 | + { |
| 27 | + Sql = sql; |
| 28 | + Argument = argument; |
| 29 | + } |
| 30 | + |
| 31 | + /// <summary> |
| 32 | + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to |
| 33 | + /// the same compatibility standards as public APIs. It may be changed or removed without notice in |
| 34 | + /// any release. You should only use it directly in your code with extreme caution and knowing that |
| 35 | + /// doing so can result in application failures when updating to a new Entity Framework Core release. |
| 36 | + /// </summary> |
| 37 | + public SqlQueryRootExpression( |
| 38 | + Type elementType, |
| 39 | + string sql, |
| 40 | + Expression argument) |
| 41 | + : base(elementType) |
| 42 | + { |
| 43 | + Sql = sql; |
| 44 | + Argument = argument; |
| 45 | + } |
| 46 | + |
| 47 | + /// <summary> |
| 48 | + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to |
| 49 | + /// the same compatibility standards as public APIs. It may be changed or removed without notice in |
| 50 | + /// any release. You should only use it directly in your code with extreme caution and knowing that |
| 51 | + /// doing so can result in application failures when updating to a new Entity Framework Core release. |
| 52 | + /// </summary> |
| 53 | + public string Sql { get; } |
| 54 | + |
| 55 | + /// <summary> |
| 56 | + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to |
| 57 | + /// the same compatibility standards as public APIs. It may be changed or removed without notice in |
| 58 | + /// any release. You should only use it directly in your code with extreme caution and knowing that |
| 59 | + /// doing so can result in application failures when updating to a new Entity Framework Core release. |
| 60 | + /// </summary> |
| 61 | + public Expression Argument { get; } |
| 62 | + |
| 63 | + /// <summary> |
| 64 | + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to |
| 65 | + /// the same compatibility standards as public APIs. It may be changed or removed without notice in |
| 66 | + /// any release. You should only use it directly in your code with extreme caution and knowing that |
| 67 | + /// doing so can result in application failures when updating to a new Entity Framework Core release. |
| 68 | + /// </summary> |
| 69 | + public override Expression DetachQueryProvider() |
| 70 | + => new SqlQueryRootExpression(ElementType, Sql, Argument); |
| 71 | + |
| 72 | + /// <summary> |
| 73 | + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to |
| 74 | + /// the same compatibility standards as public APIs. It may be changed or removed without notice in |
| 75 | + /// any release. You should only use it directly in your code with extreme caution and knowing that |
| 76 | + /// doing so can result in application failures when updating to a new Entity Framework Core release. |
| 77 | + /// </summary> |
| 78 | + protected override Expression VisitChildren(ExpressionVisitor visitor) |
| 79 | + { |
| 80 | + var argument = visitor.Visit(Argument); |
| 81 | + |
| 82 | + return argument != Argument |
| 83 | + ? new SqlQueryRootExpression(ElementType, Sql, argument) |
| 84 | + : this; |
| 85 | + } |
| 86 | + |
| 87 | + /// <summary> |
| 88 | + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to |
| 89 | + /// the same compatibility standards as public APIs. It may be changed or removed without notice in |
| 90 | + /// any release. You should only use it directly in your code with extreme caution and knowing that |
| 91 | + /// doing so can result in application failures when updating to a new Entity Framework Core release. |
| 92 | + /// </summary> |
| 93 | + protected override void Print(ExpressionPrinter expressionPrinter) |
| 94 | + { |
| 95 | + expressionPrinter.Append($"SqlQuery<{ElementType.ShortDisplayName()}>({Sql}, "); |
| 96 | + expressionPrinter.Visit(Argument); |
| 97 | + expressionPrinter.AppendLine(")"); |
| 98 | + } |
| 99 | + |
| 100 | + /// <summary> |
| 101 | + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to |
| 102 | + /// the same compatibility standards as public APIs. It may be changed or removed without notice in |
| 103 | + /// any release. You should only use it directly in your code with extreme caution and knowing that |
| 104 | + /// doing so can result in application failures when updating to a new Entity Framework Core release. |
| 105 | + /// </summary> |
| 106 | + public override bool Equals(object? obj) |
| 107 | + => obj != null |
| 108 | + && (ReferenceEquals(this, obj) |
| 109 | + || obj is SqlQueryRootExpression sqlQueryRootExpression |
| 110 | + && Equals(sqlQueryRootExpression)); |
| 111 | + |
| 112 | + private bool Equals(SqlQueryRootExpression sqlQueryRootExpression) |
| 113 | + => base.Equals(sqlQueryRootExpression) |
| 114 | + && Sql == sqlQueryRootExpression.Sql |
| 115 | + && ExpressionEqualityComparer.Instance.Equals(Argument, sqlQueryRootExpression.Argument); |
| 116 | + |
| 117 | + /// <summary> |
| 118 | + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to |
| 119 | + /// the same compatibility standards as public APIs. It may be changed or removed without notice in |
| 120 | + /// any release. You should only use it directly in your code with extreme caution and knowing that |
| 121 | + /// doing so can result in application failures when updating to a new Entity Framework Core release. |
| 122 | + /// </summary> |
| 123 | + public override int GetHashCode() |
| 124 | + => HashCode.Combine(base.GetHashCode(), Sql, ExpressionEqualityComparer.Instance.GetHashCode(Argument)); |
| 125 | +} |
0 commit comments