efcore.pg icon indicating copy to clipboard operation
efcore.pg copied to clipboard

Added Convert.ToDateTime as a supported method for translation #1297

Open TanielianVB opened this issue 5 years ago • 5 comments

It could not be so simple as that right? But I could not find the unit tests that asserted the translated query from the other Convert methods so... How could I test it?

Sorry in advance if I took an unnecessary step.

TanielianVB avatar Mar 04 '20 17:03 TanielianVB

Maybe it would have been best if I didn't created a pull request so soon. I could have asked the same referencing the commit on my fork without creating a pull request.

TanielianVB avatar Mar 04 '20 17:03 TanielianVB

@TanielianVB no worries about creating a PR!

Yeah, it actually is that simple (though a test would also be good). The reason this hasn't been done is that unlike Convert.ToInt32, Convert.ToDateTime would not work on the database in the same way as it would work in C#: the date format strings accepted by PostgreSQL and by .NET ToDateTime are very different. Let's wait for some feedback in #1297 before doing anything.

roji avatar Mar 04 '20 17:03 roji

I think that if a dev uses Convert.ToDateTime he has to know in what SQL the query will be translated. But, we can also add functions like EF.Functions.ILike to the TO_DATE and TO_TIMESTAMP functions.

TanielianVB avatar Mar 04 '20 18:03 TanielianVB

The general principle in EF is for methods to behave in the same way when translated to the server, as they would when executed on the client - this is why Convert.ToDateTime is somewhat problematic... But you're right that in any case we can provide something on EF.Functions.

roji avatar Mar 04 '20 19:03 roji

Already made all requested changes.

TanielianVB avatar Sep 11 '20 14:09 TanielianVB