Skip to content

Commit 2ed7296

Browse files
committed
Additional translations for SQL Server DateTimeOffset
Closes #26781 Closes #38074 Closes #34756
1 parent a630adf commit 2ed7296

File tree

16 files changed

+943
-29
lines changed

16 files changed

+943
-29
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,7 @@ ASALocalRun/
345345
# Local History for Visual Studio
346346
.localhistory/
347347
full.targets.txt
348+
349+
350+
# Language Server cache
351+
*.lscache

src/EFCore.SqlServer/EFCore.SqlServer.baseline.json

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,30 @@
845845
{
846846
"Member": "static System.DateTimeOffset Microsoft.EntityFrameworkCore.SqlServerDbFunctionsExtensions.DateTimeOffsetFromParts(this Microsoft.EntityFrameworkCore.DbFunctions _, int year, int month, int day, int hour, int minute, int second, int fractions, int hourOffset, int minuteOffset, int precision);"
847847
},
848+
{
849+
"Member": "static System.DateTime Microsoft.EntityFrameworkCore.SqlServerDbFunctionsExtensions.DateTrunc(this Microsoft.EntityFrameworkCore.DbFunctions _, string datepart, System.DateTime date);"
850+
},
851+
{
852+
"Member": "static System.DateTime? Microsoft.EntityFrameworkCore.SqlServerDbFunctionsExtensions.DateTrunc(this Microsoft.EntityFrameworkCore.DbFunctions _, string datepart, System.DateTime? date);"
853+
},
854+
{
855+
"Member": "static System.DateTimeOffset Microsoft.EntityFrameworkCore.SqlServerDbFunctionsExtensions.DateTrunc(this Microsoft.EntityFrameworkCore.DbFunctions _, string datepart, System.DateTimeOffset dateTimeOffset);"
856+
},
857+
{
858+
"Member": "static System.DateTimeOffset? Microsoft.EntityFrameworkCore.SqlServerDbFunctionsExtensions.DateTrunc(this Microsoft.EntityFrameworkCore.DbFunctions _, string datepart, System.DateTimeOffset? dateTimeOffset);"
859+
},
860+
{
861+
"Member": "static System.DateOnly Microsoft.EntityFrameworkCore.SqlServerDbFunctionsExtensions.DateTrunc(this Microsoft.EntityFrameworkCore.DbFunctions _, string datepart, System.DateOnly date);"
862+
},
863+
{
864+
"Member": "static System.DateOnly? Microsoft.EntityFrameworkCore.SqlServerDbFunctionsExtensions.DateTrunc(this Microsoft.EntityFrameworkCore.DbFunctions _, string datepart, System.DateOnly? date);"
865+
},
866+
{
867+
"Member": "static System.TimeOnly Microsoft.EntityFrameworkCore.SqlServerDbFunctionsExtensions.DateTrunc(this Microsoft.EntityFrameworkCore.DbFunctions _, string datepart, System.TimeOnly time);"
868+
},
869+
{
870+
"Member": "static System.TimeOnly? Microsoft.EntityFrameworkCore.SqlServerDbFunctionsExtensions.DateTrunc(this Microsoft.EntityFrameworkCore.DbFunctions _, string datepart, System.TimeOnly? time);"
871+
},
848872
{
849873
"Member": "static bool Microsoft.EntityFrameworkCore.SqlServerDbFunctionsExtensions.FreeText(this Microsoft.EntityFrameworkCore.DbFunctions _, object propertyReference, string freeText, int languageTerm);"
850874
},
@@ -2630,7 +2654,7 @@
26302654
"Member": "static System.Linq.IQueryable<Microsoft.EntityFrameworkCore.Query.FullTextSearchResult<TKey>> Microsoft.EntityFrameworkCore.SqlServerQueryableExtensions.FreeTextTable<T, TKey>(this Microsoft.EntityFrameworkCore.DbSet<T> source, string freeText, System.Linq.Expressions.Expression<System.Func<T, object>>? columnSelector = null, string? languageTerm = null, int? topN = null);"
26312655
},
26322656
{
2633-
"Member": "static System.Linq.IQueryable<Microsoft.EntityFrameworkCore.VectorSearchResult<T>> Microsoft.EntityFrameworkCore.SqlServerQueryableExtensions.VectorSearch<T, TVector>(this Microsoft.EntityFrameworkCore.DbSet<T> source, System.Linq.Expressions.Expression<System.Func<T, TVector>> vectorPropertySelector, TVector similarTo, string metric, int topN);",
2657+
"Member": "static System.Linq.IQueryable<Microsoft.EntityFrameworkCore.VectorSearchResult<T>> Microsoft.EntityFrameworkCore.SqlServerQueryableExtensions.VectorSearch<T, TVector>(this Microsoft.EntityFrameworkCore.DbSet<T> source, System.Linq.Expressions.Expression<System.Func<T, TVector>> vectorPropertySelector, TVector similarTo, string metric);",
26342658
"Stage": "Experimental"
26352659
}
26362660
]

src/EFCore.SqlServer/Extensions/SqlServerDbFunctionsExtensions.cs

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,6 +2167,202 @@ public static DateTimeOffset AtTimeZone(
21672167
string timeZone)
21682168
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(AtTimeZone)));
21692169

2170+
#region DateTrunc
2171+
2172+
/// <summary>
2173+
/// Truncates the <paramref name="date" /> to the specified <paramref name="datepart" /> precision.
2174+
/// Corresponds to SQL Server's <c>DATETRUNC(datepart, date)</c>.
2175+
/// </summary>
2176+
/// <remarks>
2177+
/// See <see href="https://aka.ms/efcore-docs-database-functions">Database functions</see>, and
2178+
/// <see href="https://aka.ms/efcore-docs-sqlserver">Accessing SQL Server and Azure SQL databases with EF Core</see>
2179+
/// for more information and examples.
2180+
/// </remarks>
2181+
/// <param name="_">The <see cref="DbFunctions" /> instance.</param>
2182+
/// <param name="datepart">
2183+
/// The datepart to truncate to. Can be one of: <c>year</c>, <c>quarter</c>, <c>month</c>, <c>dayofyear</c>,
2184+
/// <c>day</c>, <c>week</c>, <c>iso_week</c>, <c>hour</c>, <c>minute</c>, <c>second</c>, <c>millisecond</c>,
2185+
/// <c>microsecond</c>.
2186+
/// </param>
2187+
/// <param name="date">The value to truncate.</param>
2188+
/// <returns>The truncated <see cref="DateTime" /> value.</returns>
2189+
/// <seealso href="https://learn.microsoft.com/sql/t-sql/functions/datetrunc-transact-sql">SQL Server documentation for <c>DATETRUNC</c>.</seealso>
2190+
public static DateTime DateTrunc(
2191+
this DbFunctions _,
2192+
[NotParameterized] string datepart,
2193+
DateTime date)
2194+
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateTrunc)));
2195+
2196+
/// <summary>
2197+
/// Truncates the <paramref name="date" /> to the specified <paramref name="datepart" /> precision.
2198+
/// Corresponds to SQL Server's <c>DATETRUNC(datepart, date)</c>.
2199+
/// </summary>
2200+
/// <remarks>
2201+
/// See <see href="https://aka.ms/efcore-docs-database-functions">Database functions</see>, and
2202+
/// <see href="https://aka.ms/efcore-docs-sqlserver">Accessing SQL Server and Azure SQL databases with EF Core</see>
2203+
/// for more information and examples.
2204+
/// </remarks>
2205+
/// <param name="_">The <see cref="DbFunctions" /> instance.</param>
2206+
/// <param name="datepart">
2207+
/// The datepart to truncate to. Can be one of: <c>year</c>, <c>quarter</c>, <c>month</c>, <c>dayofyear</c>,
2208+
/// <c>day</c>, <c>week</c>, <c>iso_week</c>, <c>hour</c>, <c>minute</c>, <c>second</c>, <c>millisecond</c>,
2209+
/// <c>microsecond</c>.
2210+
/// </param>
2211+
/// <param name="date">The value to truncate.</param>
2212+
/// <returns>The truncated <see cref="DateTime" /> value.</returns>
2213+
/// <seealso href="https://learn.microsoft.com/sql/t-sql/functions/datetrunc-transact-sql">SQL Server documentation for <c>DATETRUNC</c>.</seealso>
2214+
public static DateTime? DateTrunc(
2215+
this DbFunctions _,
2216+
[NotParameterized] string datepart,
2217+
DateTime? date)
2218+
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateTrunc)));
2219+
2220+
/// <summary>
2221+
/// Truncates the <paramref name="dateTimeOffset" /> to the specified <paramref name="datepart" /> precision.
2222+
/// Corresponds to SQL Server's <c>DATETRUNC(datepart, date)</c>.
2223+
/// </summary>
2224+
/// <remarks>
2225+
/// See <see href="https://aka.ms/efcore-docs-database-functions">Database functions</see>, and
2226+
/// <see href="https://aka.ms/efcore-docs-sqlserver">Accessing SQL Server and Azure SQL databases with EF Core</see>
2227+
/// for more information and examples.
2228+
/// </remarks>
2229+
/// <param name="_">The <see cref="DbFunctions" /> instance.</param>
2230+
/// <param name="datepart">
2231+
/// The datepart to truncate to. Can be one of: <c>year</c>, <c>quarter</c>, <c>month</c>, <c>dayofyear</c>,
2232+
/// <c>day</c>, <c>week</c>, <c>iso_week</c>, <c>hour</c>, <c>minute</c>, <c>second</c>, <c>millisecond</c>,
2233+
/// <c>microsecond</c>.
2234+
/// </param>
2235+
/// <param name="dateTimeOffset">The value to truncate.</param>
2236+
/// <returns>The truncated <see cref="DateTimeOffset" /> value.</returns>
2237+
/// <seealso href="https://learn.microsoft.com/sql/t-sql/functions/datetrunc-transact-sql">SQL Server documentation for <c>DATETRUNC</c>.</seealso>
2238+
public static DateTimeOffset DateTrunc(
2239+
this DbFunctions _,
2240+
[NotParameterized] string datepart,
2241+
DateTimeOffset dateTimeOffset)
2242+
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateTrunc)));
2243+
2244+
/// <summary>
2245+
/// Truncates the <paramref name="dateTimeOffset" /> to the specified <paramref name="datepart" /> precision.
2246+
/// Corresponds to SQL Server's <c>DATETRUNC(datepart, date)</c>.
2247+
/// </summary>
2248+
/// <remarks>
2249+
/// See <see href="https://aka.ms/efcore-docs-database-functions">Database functions</see>, and
2250+
/// <see href="https://aka.ms/efcore-docs-sqlserver">Accessing SQL Server and Azure SQL databases with EF Core</see>
2251+
/// for more information and examples.
2252+
/// </remarks>
2253+
/// <param name="_">The <see cref="DbFunctions" /> instance.</param>
2254+
/// <param name="datepart">
2255+
/// The datepart to truncate to. Can be one of: <c>year</c>, <c>quarter</c>, <c>month</c>, <c>dayofyear</c>,
2256+
/// <c>day</c>, <c>week</c>, <c>iso_week</c>, <c>hour</c>, <c>minute</c>, <c>second</c>, <c>millisecond</c>,
2257+
/// <c>microsecond</c>.
2258+
/// </param>
2259+
/// <param name="dateTimeOffset">The value to truncate.</param>
2260+
/// <returns>The truncated <see cref="DateTimeOffset" /> value.</returns>
2261+
/// <seealso href="https://learn.microsoft.com/sql/t-sql/functions/datetrunc-transact-sql">SQL Server documentation for <c>DATETRUNC</c>.</seealso>
2262+
public static DateTimeOffset? DateTrunc(
2263+
this DbFunctions _,
2264+
[NotParameterized] string datepart,
2265+
DateTimeOffset? dateTimeOffset)
2266+
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateTrunc)));
2267+
2268+
/// <summary>
2269+
/// Truncates the <paramref name="date" /> to the specified <paramref name="datepart" /> precision.
2270+
/// Corresponds to SQL Server's <c>DATETRUNC(datepart, date)</c>.
2271+
/// </summary>
2272+
/// <remarks>
2273+
/// See <see href="https://aka.ms/efcore-docs-database-functions">Database functions</see>, and
2274+
/// <see href="https://aka.ms/efcore-docs-sqlserver">Accessing SQL Server and Azure SQL databases with EF Core</see>
2275+
/// for more information and examples.
2276+
/// </remarks>
2277+
/// <param name="_">The <see cref="DbFunctions" /> instance.</param>
2278+
/// <param name="datepart">
2279+
/// The datepart to truncate to. Can be one of: <c>year</c>, <c>quarter</c>, <c>month</c>, <c>dayofyear</c>,
2280+
/// <c>day</c>, <c>week</c>, <c>iso_week</c>, <c>hour</c>, <c>minute</c>, <c>second</c>, <c>millisecond</c>,
2281+
/// <c>microsecond</c>.
2282+
/// </param>
2283+
/// <param name="date">The value to truncate.</param>
2284+
/// <returns>The truncated <see cref="DateOnly" /> value.</returns>
2285+
/// <seealso href="https://learn.microsoft.com/sql/t-sql/functions/datetrunc-transact-sql">SQL Server documentation for <c>DATETRUNC</c>.</seealso>
2286+
public static DateOnly DateTrunc(
2287+
this DbFunctions _,
2288+
[NotParameterized] string datepart,
2289+
DateOnly date)
2290+
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateTrunc)));
2291+
2292+
/// <summary>
2293+
/// Truncates the <paramref name="date" /> to the specified <paramref name="datepart" /> precision.
2294+
/// Corresponds to SQL Server's <c>DATETRUNC(datepart, date)</c>.
2295+
/// </summary>
2296+
/// <remarks>
2297+
/// See <see href="https://aka.ms/efcore-docs-database-functions">Database functions</see>, and
2298+
/// <see href="https://aka.ms/efcore-docs-sqlserver">Accessing SQL Server and Azure SQL databases with EF Core</see>
2299+
/// for more information and examples.
2300+
/// </remarks>
2301+
/// <param name="_">The <see cref="DbFunctions" /> instance.</param>
2302+
/// <param name="datepart">
2303+
/// The datepart to truncate to. Can be one of: <c>year</c>, <c>quarter</c>, <c>month</c>, <c>dayofyear</c>,
2304+
/// <c>day</c>, <c>week</c>, <c>iso_week</c>, <c>hour</c>, <c>minute</c>, <c>second</c>, <c>millisecond</c>,
2305+
/// <c>microsecond</c>.
2306+
/// </param>
2307+
/// <param name="date">The value to truncate.</param>
2308+
/// <returns>The truncated <see cref="DateOnly" /> value.</returns>
2309+
/// <seealso href="https://learn.microsoft.com/sql/t-sql/functions/datetrunc-transact-sql">SQL Server documentation for <c>DATETRUNC</c>.</seealso>
2310+
public static DateOnly? DateTrunc(
2311+
this DbFunctions _,
2312+
[NotParameterized] string datepart,
2313+
DateOnly? date)
2314+
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateTrunc)));
2315+
2316+
/// <summary>
2317+
/// Truncates the <paramref name="time" /> to the specified <paramref name="datepart" /> precision.
2318+
/// Corresponds to SQL Server's <c>DATETRUNC(datepart, date)</c>.
2319+
/// </summary>
2320+
/// <remarks>
2321+
/// See <see href="https://aka.ms/efcore-docs-database-functions">Database functions</see>, and
2322+
/// <see href="https://aka.ms/efcore-docs-sqlserver">Accessing SQL Server and Azure SQL databases with EF Core</see>
2323+
/// for more information and examples.
2324+
/// </remarks>
2325+
/// <param name="_">The <see cref="DbFunctions" /> instance.</param>
2326+
/// <param name="datepart">
2327+
/// The datepart to truncate to. Can be one of: <c>year</c>, <c>quarter</c>, <c>month</c>, <c>dayofyear</c>,
2328+
/// <c>day</c>, <c>week</c>, <c>iso_week</c>, <c>hour</c>, <c>minute</c>, <c>second</c>, <c>millisecond</c>,
2329+
/// <c>microsecond</c>.
2330+
/// </param>
2331+
/// <param name="time">The value to truncate.</param>
2332+
/// <returns>The truncated <see cref="TimeOnly" /> value.</returns>
2333+
/// <seealso href="https://learn.microsoft.com/sql/t-sql/functions/datetrunc-transact-sql">SQL Server documentation for <c>DATETRUNC</c>.</seealso>
2334+
public static TimeOnly DateTrunc(
2335+
this DbFunctions _,
2336+
[NotParameterized] string datepart,
2337+
TimeOnly time)
2338+
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateTrunc)));
2339+
2340+
/// <summary>
2341+
/// Truncates the <paramref name="time" /> to the specified <paramref name="datepart" /> precision.
2342+
/// Corresponds to SQL Server's <c>DATETRUNC(datepart, date)</c>.
2343+
/// </summary>
2344+
/// <remarks>
2345+
/// See <see href="https://aka.ms/efcore-docs-database-functions">Database functions</see>, and
2346+
/// <see href="https://aka.ms/efcore-docs-sqlserver">Accessing SQL Server and Azure SQL databases with EF Core</see>
2347+
/// for more information and examples.
2348+
/// </remarks>
2349+
/// <param name="_">The <see cref="DbFunctions" /> instance.</param>
2350+
/// <param name="datepart">
2351+
/// The datepart to truncate to. Can be one of: <c>year</c>, <c>quarter</c>, <c>month</c>, <c>dayofyear</c>,
2352+
/// <c>day</c>, <c>week</c>, <c>iso_week</c>, <c>hour</c>, <c>minute</c>, <c>second</c>, <c>millisecond</c>,
2353+
/// <c>microsecond</c>.
2354+
/// </param>
2355+
/// <param name="time">The value to truncate.</param>
2356+
/// <returns>The truncated <see cref="TimeOnly" /> value.</returns>
2357+
/// <seealso href="https://learn.microsoft.com/sql/t-sql/functions/datetrunc-transact-sql">SQL Server documentation for <c>DATETRUNC</c>.</seealso>
2358+
public static TimeOnly? DateTrunc(
2359+
this DbFunctions _,
2360+
[NotParameterized] string datepart,
2361+
TimeOnly? time)
2362+
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateTrunc)));
2363+
2364+
#endregion DateTrunc
2365+
21702366
/// <summary>
21712367
/// Returns the starting position of the first occurrence of a pattern in a specified expression, or zero if the pattern is not found, on
21722368
/// all valid text and character data types.

src/EFCore.SqlServer/Properties/SqlServerStrings.Designer.cs

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)