forked from dotnet/efcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multiple entity support for ExecuteUpdate
Closes dotnet#31406 Fixes dotnet#31349
- Loading branch information
Showing
34 changed files
with
1,282 additions
and
643 deletions.
There are no files selected for viewing
24 changes: 12 additions & 12 deletions
24
src/EFCore.Relational/Properties/RelationalStrings.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
src/EFCore.Relational/Query/Internal/TpcTablesExpression.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
using Microsoft.EntityFrameworkCore.Query.SqlExpressions; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query.Internal; | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public sealed class TpcTablesExpression : TableExpressionBase | ||
{ | ||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public TpcTablesExpression( | ||
string? alias, | ||
IEntityType entityType, | ||
IReadOnlyList<SelectExpression> subSelectExpressions) | ||
: base(alias) | ||
{ | ||
EntityType = entityType; | ||
SelectExpressions = subSelectExpressions; | ||
} | ||
|
||
private TpcTablesExpression( | ||
string? alias, | ||
IEntityType entityType, | ||
IReadOnlyList<SelectExpression> subSelectExpressions, | ||
IEnumerable<IAnnotation>? annotations) | ||
: base(alias, annotations) | ||
{ | ||
EntityType = entityType; | ||
SelectExpressions = subSelectExpressions; | ||
} | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
[NotNull] | ||
public override string? Alias | ||
{ | ||
get => base.Alias!; | ||
internal set => base.Alias = value; | ||
} | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public IEntityType EntityType { get; } | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public IReadOnlyList<SelectExpression> SelectExpressions { get; } | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public TpcTablesExpression Prune(IReadOnlyList<string> discriminatorValues) | ||
{ | ||
var subSelectExpressions = discriminatorValues.Count == 0 | ||
? new List<SelectExpression> { SelectExpressions[0] } | ||
: SelectExpressions.Where( | ||
se => | ||
discriminatorValues.Contains((string)((SqlConstantExpression)se.Projection[^1].Expression).Value!)).ToList(); | ||
|
||
Check.DebugAssert(subSelectExpressions.Count > 0, "TPC must have at least 1 table selected."); | ||
|
||
return new TpcTablesExpression(Alias, EntityType, subSelectExpressions, GetAnnotations()); | ||
} | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
// This is implementation detail hence visitors are not supposed to see inside unless they really need to. | ||
protected override Expression VisitChildren(ExpressionVisitor visitor) | ||
=> this; | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
protected override TableExpressionBase CreateWithAnnotations(IEnumerable<IAnnotation> annotations) | ||
=> new TpcTablesExpression(Alias, EntityType, SelectExpressions, annotations); | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
protected override void Print(ExpressionPrinter expressionPrinter) | ||
{ | ||
expressionPrinter.AppendLine("("); | ||
using (expressionPrinter.Indent()) | ||
{ | ||
expressionPrinter.VisitCollection(SelectExpressions, e => e.AppendLine().AppendLine("UNION ALL")); | ||
} | ||
|
||
expressionPrinter.AppendLine() | ||
.AppendLine(") AS " + Alias); | ||
PrintAnnotations(expressionPrinter); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override bool Equals(object? obj) | ||
=> obj != null | ||
&& (ReferenceEquals(this, obj) | ||
|| obj is TpcTablesExpression tpcTablesExpression | ||
&& Equals(tpcTablesExpression)); | ||
|
||
private bool Equals(TpcTablesExpression tpcTablesExpression) | ||
{ | ||
if (!base.Equals(tpcTablesExpression) | ||
|| EntityType != tpcTablesExpression.EntityType) | ||
{ | ||
return false; | ||
} | ||
|
||
return SelectExpressions.SequenceEqual(tpcTablesExpression.SelectExpressions); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override int GetHashCode() | ||
=> HashCode.Combine(base.GetHashCode(), EntityType); | ||
} |
Oops, something went wrong.