@@ -96,6 +96,21 @@ public static Expression CreateBinaryExpression(BinaryOperatorKind binaryOperato
96
96
right = CreateTimeBinaryExpression ( right , querySettings ) ;
97
97
}
98
98
99
+ #if NET6_0
100
+ if ( ( IsType < DateOnly > ( leftUnderlyingType ) & & IsDate ( rightUnderlyingType ) ) ||
101
+ ( IsDate ( leftUnderlyingType ) && IsType < DateOnly > ( rightUnderlyingType ) ) )
102
+ {
103
+ left = CreateDateBinaryExpression ( left , querySettings ) ;
104
+ right = CreateDateBinaryExpression ( right , querySettings ) ;
105
+ }
106
+ else if ( ( IsType < TimeOnly > ( leftUnderlyingType ) & & IsTimeOfDay ( rightUnderlyingType ) ) ||
107
+ ( IsTimeOfDay ( leftUnderlyingType ) && IsType < TimeOnly > ( rightUnderlyingType ) ) )
108
+ {
109
+ left = CreateTimeBinaryExpression ( left , querySettings ) ;
110
+ right = CreateTimeBinaryExpression ( right , querySettings ) ;
111
+ }
112
+ #endif
113
+
99
114
if ( left . Type != right . Type )
100
115
{
101
116
// one of them must be nullable and the other is not.
@@ -381,6 +396,16 @@ private static Expression GetProperty(Expression source, string propertyName, OD
381
396
{
382
397
return MakePropertyAccess ( ClrCanonicalFunctions . TimeSpanProperties [ propertyName ] , source , querySettings ) ;
383
398
}
399
+ #if NET6_0
400
+ else if ( IsType < DateOnly > ( source . Type ) )
401
+ {
402
+ return MakePropertyAccess ( ClrCanonicalFunctions . DateOnlyProperties [ propertyName ] , source , querySettings ) ;
403
+ }
404
+ else if ( IsType < TimeOnly > ( source . Type ) )
405
+ {
406
+ return MakePropertyAccess ( ClrCanonicalFunctions . TimeOnlyProperties [ propertyName ] , source , querySettings ) ;
407
+ }
408
+ #endif
384
409
385
410
return source ;
386
411
}
@@ -413,9 +438,9 @@ private static Expression CreateTimeBinaryExpression(Expression source, ODataQue
413
438
Expression second = GetProperty ( source , ClrCanonicalFunctions . SecondFunctionName , querySettings ) ;
414
439
Expression milliSecond = GetProperty ( source , ClrCanonicalFunctions . MillisecondFunctionName , querySettings ) ;
415
440
416
- Expression hourTicks = Expression . Multiply ( Expression . Convert ( hour , typeof ( long ) ) , Expression . Constant ( TimeOfDay . TicksPerHour ) ) ;
417
- Expression minuteTicks = Expression . Multiply ( Expression . Convert ( minute , typeof ( long ) ) , Expression . Constant ( TimeOfDay . TicksPerMinute ) ) ;
418
- Expression secondTicks = Expression . Multiply ( Expression . Convert ( second , typeof ( long ) ) , Expression . Constant ( TimeOfDay . TicksPerSecond ) ) ;
441
+ Expression hourTicks = Expression . Multiply ( Expression . Convert ( hour , typeof ( long ) ) , Expression . Constant ( TimeSpan . TicksPerHour , typeof ( long ) ) ) ;
442
+ Expression minuteTicks = Expression . Multiply ( Expression . Convert ( minute , typeof ( long ) ) , Expression . Constant ( TimeSpan . TicksPerMinute , typeof ( long ) ) ) ;
443
+ Expression secondTicks = Expression . Multiply ( Expression . Convert ( second , typeof ( long ) ) , Expression . Constant ( TimeSpan . TicksPerSecond , typeof ( long ) ) ) ;
419
444
420
445
// return (hour * TicksPerHour + minute * TicksPerMinute + second * TicksPerSecond + millisecond)
421
446
Expression result = Expression . Add ( hourTicks , Expression . Add ( minuteTicks , Expression . Add ( secondTicks , Expression . Convert ( milliSecond , typeof ( long ) ) ) ) ) ;
@@ -451,6 +476,18 @@ private static Expression ConvertToDateTimeRelatedConstExpression(Expression sou
451
476
{
452
477
return Expression . Constant ( timeOfDay . Value , typeof ( TimeOfDay ) ) ;
453
478
}
479
+
480
+ #if NET6_0
481
+ if ( parameterizedConstantValue is DateOnly dateOnly )
482
+ {
483
+ return Expression . Constant ( dateOnly , typeof ( DateOnly ) ) ;
484
+ }
485
+
486
+ else if ( parameterizedConstantValue is TimeOnly timeOnly )
487
+ {
488
+ return Expression . Constant ( timeOnly , typeof ( TimeOnly ) ) ;
489
+ }
490
+ #endif
454
491
}
455
492
456
493
return source ;
@@ -468,21 +505,34 @@ public static bool IsDoubleOrDecimal(Type type)
468
505
469
506
public static bool IsDateAndTimeRelated ( Type type )
470
507
{
471
- return IsType < Date > ( type ) ||
472
- IsType < DateTime > ( type ) ||
473
- IsType < DateTimeOffset > ( type ) ||
474
- IsType < TimeOfDay > ( type ) ||
475
- IsType < TimeSpan > ( type ) ;
508
+ return IsType < Date > ( type )
509
+ || IsType < DateTime > ( type )
510
+ || IsType < DateTimeOffset > ( type )
511
+ || IsType < TimeOfDay > ( type )
512
+ || IsType < TimeSpan > ( type )
513
+ #if NET6_0
514
+ || IsType < DateOnly > ( type )
515
+ || IsType < TimeOnly > ( type )
516
+ #endif
517
+ ;
476
518
}
477
519
478
520
public static bool IsDateRelated ( Type type )
479
521
{
522
+ #if NET6_0
523
+ return IsType < Date > ( type ) || IsType < DateTime > ( type ) || IsType < DateTimeOffset > ( type ) || IsType < DateOnly > ( type ) ;
524
+ #else
480
525
return IsType < Date > ( type ) || IsType < DateTime > ( type ) || IsType < DateTimeOffset > ( type ) ;
526
+ #endif
481
527
}
482
528
483
529
public static bool IsTimeRelated ( Type type )
484
530
{
531
+ #if NET6_0
532
+ return IsType < TimeOfDay > ( type ) || IsType < DateTime > ( type ) || IsType < DateTimeOffset > ( type ) || IsType < TimeSpan > ( type ) || IsType < TimeOnly > ( type ) ;
533
+ #else
485
534
return IsType < TimeOfDay > ( type ) || IsType < DateTime > ( type ) || IsType < DateTimeOffset > ( type ) || IsType < TimeSpan > ( type ) ;
535
+ #endif
486
536
}
487
537
488
538
public static bool IsDateOrOffset ( Type type )
@@ -510,6 +560,18 @@ public static bool IsDate(Type type)
510
560
return IsType < Date > ( type ) ;
511
561
}
512
562
563
+ #if NET6_0
564
+ public static bool IsDateOnly ( this Type type )
565
+ {
566
+ return IsType < DateOnly > ( type ) ;
567
+ }
568
+
569
+ public static bool IsTimeOnly ( this Type type )
570
+ {
571
+ return IsType < TimeOnly > ( type ) ;
572
+ }
573
+ #endif
574
+
513
575
public static bool IsInteger ( Type type )
514
576
{
515
577
return IsType < short > ( type ) || IsType < int > ( type ) || IsType < long > ( type ) ;
0 commit comments