@@ -282,74 +282,42 @@ SqlExpression Upper()
282282 }
283283
284284 private SqlExpression ? TranslateDateTime ( SqlExpression instance , MemberInfo member , Type returnType )
285- {
286- switch ( member . Name )
285+ => member . Name switch
287286 {
288- case "Year" :
289- case "Years" :
290- return GetDatePartExpression ( instance , "year" ) ;
291-
292- case "Month" :
293- case "Months" :
294- return GetDatePartExpression ( instance , "month" ) ;
295-
296- case "DayOfYear" :
297- return GetDatePartExpression ( instance , "doy" ) ;
298-
299- case "Day" :
300- case "Days" :
301- return GetDatePartExpression ( instance , "day" ) ;
302-
303- case "Hour" :
304- case "Hours" :
305- return GetDatePartExpression ( instance , "hour" ) ;
306-
307- case "Minute" :
308- case "Minutes" :
309- return GetDatePartExpression ( instance , "minute" ) ;
310-
311- case "Second" :
312- case "Seconds" :
313- return GetDatePartExpression ( instance , "second" , true ) ;
314-
315- case "Millisecond" :
316- case "Milliseconds" :
317- return null ; // Too annoying
318-
319- case "DayOfWeek" :
320- // Unlike DateTime.DayOfWeek, NodaTime's IsoDayOfWeek enum doesn't exactly correspond to PostgreSQL's
321- // values returned by date_part('dow', ...): in NodaTime Sunday is 7 and not 0, which is None.
322- // So we generate a CASE WHEN expression to translate PostgreSQL's 0 to 7.
323- var getValueExpression = GetDatePartExpression ( instance , "dow" , true ) ;
324- // TODO: Can be simplified once https://github.com/aspnet/EntityFrameworkCore/pull/16726 is in
325- return
326- _sqlExpressionFactory . Case (
327- new [ ]
328- {
329- new CaseWhenClause (
330- _sqlExpressionFactory . Equal ( getValueExpression , _sqlExpressionFactory . Constant ( 0 ) ) ,
331- _sqlExpressionFactory . Constant ( 7 ) )
332- } ,
333- getValueExpression
334- ) ;
287+ "Year" or "Years" => GetDatePartExpression ( instance , "year" ) ,
288+ "Month" or "Months" => GetDatePartExpression ( instance , "month" ) ,
289+ "DayOfYear" => GetDatePartExpression ( instance , "doy" ) ,
290+ "Day" or "Days" => GetDatePartExpression ( instance , "day" ) ,
291+ "Hour" or "Hours" => GetDatePartExpression ( instance , "hour" ) ,
292+ "Minute" or "Minutes" => GetDatePartExpression ( instance , "minute" ) ,
293+ "Second" or "Seconds" => GetDatePartExpression ( instance , "second" , true ) ,
294+ "Millisecond" or "Milliseconds" => null , // Too annoying
295+
296+ // Unlike DateTime.DayOfWeek, NodaTime's IsoDayOfWeek enum doesn't exactly correspond to PostgreSQL's
297+ // values returned by date_part('dow', ...): in NodaTime Sunday is 7 and not 0, which is None.
298+ // So we generate a CASE WHEN expression to translate PostgreSQL's 0 to 7.
299+ "DayOfWeek" when GetDatePartExpression ( instance , "dow" , true ) is var getValueExpression
300+ => _sqlExpressionFactory . Case (
301+ getValueExpression ,
302+ new [ ]
303+ {
304+ new CaseWhenClause ( _sqlExpressionFactory . Constant ( 0 ) , _sqlExpressionFactory . Constant ( 7 ) )
305+ } ,
306+ getValueExpression ) ,
335307
336308 // PG allows converting a timestamp directly to date, truncating the time; but given a timestamptz, it performs a time zone
337309 // conversion (based on TimeZone), which we don't want (so avoid translating except on timestamp).
338310 // The translation for ZonedDateTime.Date converts to timestamp before ending up here.
339- case "Date" when instance . TypeMapping is TimestampLocalDateTimeMapping or LegacyTimestampInstantMapping :
340- return _sqlExpressionFactory . Convert ( instance , typeof ( LocalDate ) , _typeMappingSource . FindMapping ( typeof ( LocalDate ) ) ! ) ;
341-
342- case "TimeOfDay" :
343- // TODO: Technically possible simply via casting to PG time,
344- // but ExplicitCastExpression only allows casting to PG types that
345- // are default-mapped from CLR types (timespan maps to interval,
346- // which timestamp cannot be cast into)
347- return null ;
348-
349- default :
350- return null ;
351- }
352- }
311+ "Date" when instance . TypeMapping is TimestampLocalDateTimeMapping or LegacyTimestampInstantMapping
312+ => _sqlExpressionFactory . Convert ( instance , typeof ( LocalDate ) , _typeMappingSource . FindMapping ( typeof ( LocalDate ) ) ! ) ,
313+
314+ "TimeOfDay" => _sqlExpressionFactory . Convert (
315+ instance ,
316+ typeof ( LocalTime ) ,
317+ _typeMappingSource . FindMapping ( typeof ( LocalTime ) , storeTypeName : "time" ) ) ,
318+
319+ _ => null
320+ } ;
353321
354322 /// <summary>
355323 /// Constructs the date_part expression.
0 commit comments