Skip to content

Commit

Permalink
Don't implement ITableBasedExpression in FromSqlExpression (#28699)
Browse files Browse the repository at this point in the history
Circumventing #28667 in different way
  • Loading branch information
smitpatel authored Aug 13, 2022
1 parent 7abc751 commit ba92471
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/EFCore.Relational/Query/SqlExpressionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,8 @@ private void AddConditions(SelectExpression selectExpression, IEntityType entity
return;
}

var table = ((ITableBasedExpression)selectExpression.Tables[0]).Table;
var firstTable = selectExpression.Tables[0];
var table = (firstTable as FromSqlExpression)?.Table ?? ((ITableBasedExpression)firstTable).Table;
if (table.IsOptional(entityType))
{
var entityProjectionExpression = GetMappedEntityProjectionExpression(selectExpression);
Expand Down
10 changes: 6 additions & 4 deletions src/EFCore.Relational/Query/SqlExpressions/FromSqlExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions;
/// not used in application code.
/// </para>
/// </summary>
public class FromSqlExpression : TableExpressionBase, IClonableTableExpressionBase, ITableBasedExpression
public class FromSqlExpression : TableExpressionBase, IClonableTableExpressionBase
{
private readonly ITableBase _table;

Expand Down Expand Up @@ -72,6 +72,11 @@ public override string? Alias
/// </summary>
public virtual Expression Arguments { get; }

/// <summary>
/// The <see cref="ITableBase"/> associated with given table source if any, <see langword="null" /> otherwise.
/// </summary>
public virtual ITableBase? Table => _table;

/// <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.
Expand All @@ -87,9 +92,6 @@ public virtual FromSqlExpression Update(Expression arguments)
protected override TableExpressionBase CreateWithAnnotations(IEnumerable<IAnnotation> annotations)
=> new FromSqlExpression(Alias, _table, Sql, Arguments, annotations);

/// <inheritdoc />
ITableBase ITableBasedExpression.Table => _table;

/// <inheritdoc />
protected override Expression VisitChildren(ExpressionVisitor visitor)
=> this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ internal SelectExpression(IEntityType entityType, TableExpressionBase tableExpre
throw new InvalidOperationException(RelationalStrings.SelectExpressionNonTphWithCustomTable(entityType.DisplayName()));
}

var table = ((ITableBasedExpression)tableExpressionBase).Table;
var table = (tableExpressionBase as FromSqlExpression)?.Table ?? ((ITableBasedExpression)tableExpressionBase).Table;
var tableReferenceExpression = new TableReferenceExpression(this, tableExpressionBase.Alias!);
AddTable(tableExpressionBase, tableReferenceExpression);

Expand Down

0 comments on commit ba92471

Please sign in to comment.