nhibernate-core
nhibernate-core copied to clipboard
Fix Linq .Second bug for PostgreSQL et al.
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.
Mysql seems to be failing because it needs to use floor
instead of cast
. I had this issue with my local postgres.