nhibernate-core icon indicating copy to clipboard operation
nhibernate-core copied to clipboard

Fix Linq .Second bug for PostgreSQL et al.

Open gliljas opened this issue 10 months ago • 1 comments

Fix for #3525

The actual fix was adding a new HQL function "secondtruncated", which is used if it is available, otherwise it falls back to the old "second". Another option would be to fix the "second" function in the dialects where it doesn't work, but that could be considered a more breaking change. As mentioned in the issue, Hibernate has defined "second" to actually include fractional seconds, and have adjusted the dialects where the corresponding SQL function truncates.

The most changes were in DateTimeTests.cs. I really wanted to use that test class since it already tests exactly this (but not seconds), but to get fractional seconds into the Northwind dataset was a bit icky, so I opted to create specific test data.

I used the approach of comparing the result from the LINQ query with the result from the same query run in memory. Of course that doesn't work in scenarios with null, case sensitivity etc., but here it works just fine.

The MySQL test fails on Github, for some reason. I can't make it fail locally.

gliljas avatar Apr 19 '24 07:04 gliljas

Mysql seems to be failing because it needs to use floor instead of cast. I had this issue with my local postgres.

hazzik avatar May 30 '24 01:05 hazzik