diff --git a/src/EFCore.PG/Query/Internal/NpgsqlQuerySqlGenerator.cs b/src/EFCore.PG/Query/Internal/NpgsqlQuerySqlGenerator.cs index 3b9a1d49f..bcbc9dd08 100644 --- a/src/EFCore.PG/Query/Internal/NpgsqlQuerySqlGenerator.cs +++ b/src/EFCore.PG/Query/Internal/NpgsqlQuerySqlGenerator.cs @@ -1493,7 +1493,7 @@ protected override bool TryGetOperatorInfo(SqlExpression expression, out int pre PgBinaryExpression => (1000, false), CollateExpression => (1000, false), - AtTimeZoneExpression => (1000, false), + AtTimeZoneExpression => (1100, false), InExpression => (900, false), PgJsonTraversalExpression => (1000, false), PgArrayIndexExpression => (1500, false), diff --git a/test/EFCore.PG.FunctionalTests/Query/OperatorsQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/OperatorsQueryNpgsqlTest.cs index ab04dc9df..3bbbe57d7 100644 --- a/test/EFCore.PG.FunctionalTests/Query/OperatorsQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/OperatorsQueryNpgsqlTest.cs @@ -125,6 +125,41 @@ LIMIT 2 """); } + [ConditionalFact] + public virtual async Task AtTimeZone_and_addition() + { + var contextFactory = await InitializeAsync( + seed: context => + { + context.Set().AddRange( + new OperatorEntityDateTime { Id = 1, Value = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc) }, + new OperatorEntityDateTime { Id = 2, Value = new DateTime(2020, 2, 1, 0, 0, 0, DateTimeKind.Utc) }); + context.SaveChanges(); + }, + onModelCreating: modelBuilder => modelBuilder.Entity().Property(x => x.Id).ValueGeneratedNever()); + + await using var context = contextFactory.CreateContext(); + + var result = await context.Set() + .Where(b => new DateOnly(2020, 1, 15) > DateOnly.FromDateTime(b.Value.AddDays(1))) + .SingleAsync(); + + Assert.Equal(1, result.Id); + + AssertSql( + """ +SELECT o."Id", o."Value" +FROM "OperatorEntityDateTime" AS o +WHERE DATE '2020-01-15' > CAST((o."Value" + INTERVAL '1 days') AT TIME ZONE 'UTC' AS date) +LIMIT 2 +"""); + } + + public class OperatorEntityDateTime : OperatorEntityBase + { + public DateTime Value { get; set; } + } + protected override void Seed(OperatorsContext ctx) { ctx.Set().AddRange(ExpectedData.OperatorEntitiesString);