Skip to content

Commit

Permalink
Redo query column/table relationship without TableReferenceExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
roji committed Jan 14, 2024
1 parent a7c0ab5 commit b0607d0
Show file tree
Hide file tree
Showing 27 changed files with 1,518 additions and 2,062 deletions.
2 changes: 2 additions & 0 deletions EFCore.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<s:Boolean x:Key="/Default/UserDictionary/Words/=annotatables/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=autoscale/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=batchable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Comparers/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=composability/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=composable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Constructible/@EntryIndexedValue">True</s:Boolean>
Expand Down Expand Up @@ -326,6 +327,7 @@ The .NET Foundation licenses this file to you under the MIT license.&#xD;
<s:Boolean x:Key="/Default/UserDictionary/Words/=sargable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=savepoints/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Scaffolder/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=select_0027s/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=shaper/@EntryIndexedValue">True</s:Boolean>

<s:Boolean x:Key="/Default/UserDictionary/Words/=singularized/@EntryIndexedValue">True</s:Boolean>
Expand Down
126 changes: 0 additions & 126 deletions src/EFCore.Relational/Query/Internal/TableReferenceExpression.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public partial class RelationalQueryableMethodTranslatingExpressionVisitor
return null;
}

var selectExpression = (SelectExpression)source.QueryExpression;

// Translate the setters: the left (property) selectors get translated to ColumnExpressions, the right (value) selectors to
// arbitrary SqlExpressions.
// Note that if the query isn't natively supported, we'll do a pushdown (see PushdownWithPkInnerJoinPredicate below); if that
Expand All @@ -61,10 +63,17 @@ public partial class RelationalQueryableMethodTranslatingExpressionVisitor
return null;
}

if (targetTable is TpcTablesExpression tpcTablesExpression)
{
AddTranslationErrorDetails(
RelationalStrings.ExecuteOperationOnTPC(
nameof(RelationalQueryableExtensions.ExecuteUpdate), tpcTablesExpression.EntityType.DisplayName()));
return null;
}

// Check if the provider has a native translation for the update represented by the select expression.
// The default relational implementation handles simple, universally-supported cases (i.e. no operators except for predicate).
// Providers may override IsValidSelectExpressionForExecuteUpdate to add support for more cases via provider-specific UPDATE syntax.
var selectExpression = (SelectExpression)source.QueryExpression;
if (IsValidSelectExpressionForExecuteUpdate(selectExpression, targetTable, out var tableExpression))
{
selectExpression.ReplaceProjection(new List<Expression>());
Expand Down Expand Up @@ -114,10 +123,8 @@ bool TranslateSetters(
[NotNullWhen(true)] out List<ColumnValueSetter>? translatedSetters,
[NotNullWhen(true)] out TableExpressionBase? targetTable)
{
var selectExpression = (SelectExpression)source.QueryExpression;

targetTable = null;
TableExpressionBase? tempTargetTable = null;
string? targetTableAlias = null;
var tempTranslatedSetters = new List<ColumnValueSetter>();
translatedSetters = null;

Expand Down Expand Up @@ -165,29 +172,21 @@ bool TranslateSetters(
}
}

targetTable = tempTargetTable;
translatedSetters = tempTranslatedSetters;

Check.DebugAssert(targetTable is not null, "Target table should have a value");

if (targetTable is TpcTablesExpression tpcTablesExpression)
{
AddTranslationErrorDetails(
RelationalStrings.ExecuteOperationOnTPC(
nameof(RelationalQueryableExtensions.ExecuteUpdate), tpcTablesExpression.EntityType.DisplayName()));
return false;
}
Check.DebugAssert(targetTableAlias is not null, "Target table alias should have a value");
targetTable = selectExpression.Tables.First(t => t.GetRequiredAlias() == targetTableAlias);

return true;

bool IsColumnOnSameTable(ColumnExpression column, LambdaExpression propertySelector)
{
if (tempTargetTable is null)
if (targetTableAlias is null)
{
tempTargetTable = column.Table;
targetTableAlias = column.TableAlias;
targetTablePropertySelector = propertySelector;
}
else if (!ReferenceEquals(column.Table, tempTargetTable))
else if (!ReferenceEquals(column.TableAlias, targetTableAlias))
{
AddTranslationErrorDetails(
RelationalStrings.MultipleTablesInExecuteUpdate(
Expand Down
Loading

0 comments on commit b0607d0

Please sign in to comment.