diff --git a/src/EFCore.SqlServer/Extensions/SqlServerDbSetExtensions.cs b/src/EFCore.SqlServer/Extensions/SqlServerDbSetExtensions.cs index 9ceb8d59b31..9319a7e1a8d 100644 --- a/src/EFCore.SqlServer/Extensions/SqlServerDbSetExtensions.cs +++ b/src/EFCore.SqlServer/Extensions/SqlServerDbSetExtensions.cs @@ -1,8 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System; -using System.Linq; using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.SqlServer.Query.Internal; @@ -21,15 +19,18 @@ public static class SqlServerDbSetExtensions /// Applies temporal 'AsOf' operation on the given DbSet, which only returns elements that were present in the database at a given point in time. /// /// + /// Temporal information is stored in UTC format on the database, so any arguments in local time may lead to unexpected results. + /// + /// /// Temporal queries are always set as 'NoTracking'. /// /// /// Source DbSet on which the temporal operation is applied. - /// representing a point in time for which the results should be returned. + /// representing a point in time for which the results should be returned. /// An representing the entities at a given point in time. public static IQueryable TemporalAsOf( this DbSet source, - DateTime pointInTime) + DateTime utcPointInTime) where TEntity : class { Check.NotNull(source, nameof(source)); @@ -39,7 +40,7 @@ public static IQueryable TemporalAsOf( return queryableSource.Provider.CreateQuery( GenerateTemporalAsOfQueryRoot( queryableSource, - pointInTime)).AsNoTracking(); + utcPointInTime)).AsNoTracking(); } /// @@ -53,17 +54,20 @@ public static IQueryable TemporalAsOf( /// All versions of entities in that were present within the time range are returned, so it is possible to return multiple entities with the same key. /// /// + /// Temporal information is stored in UTC format on the database, so any arguments in local time may lead to unexpected results. + /// + /// /// Temporal queries are always set as 'NoTracking'. /// /// /// Source DbSet on which the temporal operation is applied. - /// Point in time representing the start of the period for which results should be returned. - /// Point in time representing the end of the period for which results should be returned. + /// Point in time representing the start of the period for which results should be returned. + /// Point in time representing the end of the period for which results should be returned. /// An representing the entities present in a given time range. public static IQueryable TemporalFromTo( this DbSet source, - DateTime from, - DateTime to) + DateTime utcFrom, + DateTime utcTo) where TEntity : class { Check.NotNull(source, nameof(source)); @@ -73,8 +77,8 @@ public static IQueryable TemporalFromTo( return queryableSource.Provider.CreateQuery( GenerateRangeTemporalQueryRoot( queryableSource, - from, - to, + utcFrom, + utcTo, TemporalOperationType.FromTo)).AsNoTracking(); } @@ -89,17 +93,20 @@ public static IQueryable TemporalFromTo( /// All versions of entities in that were present within the time range are returned, so it is possible to return multiple entities with the same key. /// /// + /// Temporal information is stored in UTC format on the database, so any arguments in local time may lead to unexpected results. + /// + /// /// Temporal queries are always set as 'NoTracking'. /// /// /// Source DbSet on which the temporal operation is applied. - /// Point in time representing the start of the period for which results should be returned. - /// Point in time representing the end of the period for which results should be returned. + /// Point in time representing the start of the period for which results should be returned. + /// Point in time representing the end of the period for which results should be returned. /// An representing the entities present in a given time range. public static IQueryable TemporalBetween( this DbSet source, - DateTime from, - DateTime to) + DateTime utcFrom, + DateTime utcTo) where TEntity : class { Check.NotNull(source, nameof(source)); @@ -109,8 +116,8 @@ public static IQueryable TemporalBetween( return queryableSource.Provider.CreateQuery( GenerateRangeTemporalQueryRoot( queryableSource, - from, - to, + utcFrom, + utcTo, TemporalOperationType.Between)).AsNoTracking(); } @@ -125,17 +132,20 @@ public static IQueryable TemporalBetween( /// All versions of entities in that were present within the time range are returned, so it is possible to return multiple entities with the same key. /// /// + /// Temporal information is stored in UTC format on the database, so any arguments in local time may lead to unexpected results. + /// + /// /// Temporal queries are always set as 'NoTracking'. /// /// /// Source DbSet on which the temporal operation is applied. - /// Point in time representing the start of the period for which results should be returned. - /// Point in time representing the end of the period for which results should be returned. + /// Point in time representing the start of the period for which results should be returned. + /// Point in time representing the end of the period for which results should be returned. /// An representing the entities present in a given time range. public static IQueryable TemporalContainedIn( this DbSet source, - DateTime from, - DateTime to) + DateTime utcFrom, + DateTime utcTo) where TEntity : class { Check.NotNull(source, nameof(source)); @@ -145,8 +155,8 @@ public static IQueryable TemporalContainedIn( return queryableSource.Provider.CreateQuery( GenerateRangeTemporalQueryRoot( queryableSource, - from, - to, + utcFrom, + utcTo, TemporalOperationType.ContainedIn)).AsNoTracking(); }