-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Add AtTimeZoneExpression and some relevant translations #26972
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
91 changes: 91 additions & 0 deletions
91
src/EFCore.Relational/Query/SqlExpressions/AtTimeZoneExpression.cs
This file contains hidden or 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,91 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions; | ||
|
||
/// <summary> | ||
/// <para> | ||
/// An expression that represents an AT TIME ZONE operation in a SQL tree. | ||
/// </para> | ||
/// <para> | ||
/// This type is typically used by database providers (and other extensions). It is generally | ||
/// not used in application code. | ||
/// </para> | ||
/// </summary> | ||
public class AtTimeZoneExpression : SqlExpression | ||
{ | ||
/// <summary> | ||
/// Creates a new instance of the <see cref="AtTimeZoneExpression" /> class. | ||
/// </summary> | ||
/// <param name="operand">The operand on which to perform the time zone conversion.</param> | ||
/// <param name="timeZone">The time zone to convert to.</param> | ||
/// <param name="type">The <see cref="Type" /> of the expression.</param> | ||
/// <param name="typeMapping">The <see cref="RelationalTypeMapping" /> associated with the expression.</param> | ||
public AtTimeZoneExpression( | ||
SqlExpression operand, | ||
SqlExpression timeZone, | ||
Type type, | ||
RelationalTypeMapping? typeMapping) | ||
: base(type, typeMapping) | ||
{ | ||
Operand = operand; | ||
TimeZone = timeZone; | ||
} | ||
|
||
/// <summary> | ||
/// The input operand on which to apply the time zone. | ||
/// </summary> | ||
public virtual SqlExpression Operand { get; } | ||
|
||
/// <summary> | ||
/// The time zone to be applied. | ||
/// </summary> | ||
public virtual SqlExpression TimeZone { get; } | ||
|
||
/// <inheritdoc /> | ||
protected override Expression VisitChildren(ExpressionVisitor visitor) | ||
{ | ||
var operand = (SqlExpression)visitor.Visit(Operand); | ||
var timeZone = (SqlExpression)visitor.Visit(TimeZone); | ||
|
||
return Update(operand, timeZone); | ||
} | ||
|
||
/// <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. | ||
/// </summary> | ||
/// <param name="operand">The <see cref="Operand" /> property of the result.</param> | ||
/// <param name="timeZone">The <see cref="TimeZone" /> property of the result.</param> | ||
/// <returns>This expression if no children changed, or an expression with the updated children.</returns> | ||
public virtual AtTimeZoneExpression Update(SqlExpression operand, SqlExpression timeZone) | ||
=> operand != Operand || timeZone != TimeZone | ||
? new AtTimeZoneExpression(operand, timeZone, Type, TypeMapping) | ||
: this; | ||
|
||
/// <inheritdoc /> | ||
protected override void Print(ExpressionPrinter expressionPrinter) | ||
{ | ||
expressionPrinter.Visit(Operand); | ||
|
||
expressionPrinter.Append(" AT TIME ZONE "); | ||
|
||
expressionPrinter.Visit(TimeZone); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override bool Equals(object? obj) | ||
=> obj != null | ||
&& (ReferenceEquals(this, obj) | ||
|| obj is AtTimeZoneExpression atTimeZoneExpression | ||
&& Equals(atTimeZoneExpression)); | ||
|
||
private bool Equals(AtTimeZoneExpression atTimeZoneExpression) | ||
=> base.Equals(atTimeZoneExpression) | ||
&& Operand.Equals(atTimeZoneExpression.Operand) | ||
&& TimeZone.Equals(atTimeZoneExpression.TimeZone); | ||
|
||
/// <inheritdoc /> | ||
public override int GetHashCode() | ||
=> HashCode.Combine(base.GetHashCode(), Operand, TimeZone); | ||
} |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.