Fix Linq .Second bug for PostgreSQL et al. #3528
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.