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 16, 2024
1 parent 942f693 commit 767a4f2
Show file tree
Hide file tree
Showing 27 changed files with 1,524 additions and 2,067 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 @@ -58,6 +58,14 @@ 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.
Expand Down Expand Up @@ -111,19 +119,17 @@ 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;

LambdaExpression? propertySelector;
Expression? targetTablePropertySelector = null;

for (var i = 0; i < setters.Count; i++)
foreach (var setter in setters)
{
(propertySelector, var valueSelector) = setters[i];
(propertySelector, var valueSelector) = setter;
var propertySelectorBody = RemapLambdaBody(source, propertySelector).UnwrapTypeConversion(out _);

switch (_sqlTranslator.TranslateProjection(propertySelectorBody))
Expand Down Expand Up @@ -162,29 +168,22 @@ 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");
var selectExpression = (SelectExpression)source.QueryExpression;
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 767a4f2

Please sign in to comment.