0

After upgrading from EF 2.1.x to 3.1.x this query started to throw

Can't write CLR type System.DateTime with handler type IntervalHandler

But I'm not really sure how can I "nicely" rewrite this query, so performing math on those dates isn't going to explode

input is IQueryable

input.OrderBy
(
        x =>
        (x.RegistrationDate == null ? new DateTime(1990,1, 1).Date : x.RegistrationDate.Value.Date)
        -
        (x.InvoiceDate == null ? new DateTime(1990, 1, 1).Date : x.InvoiceDate.Value.Date)
)

Both of those Dates have type: timestamp without time zone in database

PostgreSQL 8.4.20 64-bit

<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />

Thanks in advance!

Joelty
  • 1,751
  • 5
  • 22
  • 64
  • 1
    What happens if you use `var bob = new DateTime(1990,1, 1);` then `x => ((x.RegistrationDate ?? bob)- (x.InvoiceDate ?? bob)`? – mjwills Sep 23 '20 at 07:51
  • @mjwills Thank you, it works fine, please write it as an answer so I can accept. PS: It's not possible to use property `.Date` this way? so it will take hours/minutes and so on into consideration while performing query, yup? – Joelty Sep 23 '20 at 08:08
  • Does `x => ((x.RegistrationDate?.Date ?? bob)- (x.InvoiceDate?.Date ?? bob)` work? – mjwills Sep 23 '20 at 09:01
  • @mjwills I tried it, it doesn't even compile `An expression tree lambda may not contain a null propagating operator.` But currently provided solution is fine – Joelty Sep 23 '20 at 12:18
  • https://stackoverflow.com/a/44681421/10522960 – Joelty Sep 23 '20 at 12:20

0 Answers0