-
-
Notifications
You must be signed in to change notification settings - Fork 460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing support for DateTimeOffset with offset in LINQ queries? #3590
Comments
It's a limitation in more recent versions of Npgsql. And the "fix" is probably going to be just having Marten quietly convert the time to UTC for you anyway. This is going to be an "I take pull requests" issue most likely if you're interested. |
@Torgeir-Hansen Meh, I'm trying to do a bug sweep and release today. I'll take a shot at this, but all it's going to do is make a ToUniversal() conversion as it builds the NpgsqlCommand. |
Technically it's that easy. But I prefer in not doing so, rather move the conversion to users's code and leave the exception here. Why? |
Consider using NodaTime data types since they are supported by both Npgsql and Marten. I implemented a basic appointment booking system a couple of months ago with Marten where timezone handling was of the essence. I'll have to get back to you tomorrow with the details as i am not 100% sure of whether or not i queried against dates, but i remember that nodatime played a role (never heard of it before that). Maybe i stored as Utc and just stored the offset using nodatime. Will get back you on that, middle of the night here. |
Well, just checked and I essentially store the IANATimeZone and UTC. I use the NodaTime utility functions/types to help with conversion and display ( Well in my case I actually store the DateTimeOffset for other reasons (see NodaTime's I agree that it's probably better to let Marten blow up instead of doing silent conversions that would cause folks to lose the timezone information without realizing it. I don't think it is a bug, people should simply clarify their design. Even at a conceptual level, querying against a DateTimeOffset is a confusing concept (one may argue that the database should compare by converting to utc, but in many cases folks may actually have a different domain-specific comparison logic in mind). I think it's actually helpful to throw this exception to invite people to revisit their design early in the development process. |
The NodaTime LINQ support is a nightmare too, no free lunch here. |
Hi,
When I try to query with LINQ using a DateTimeOffset with a timezone, it throws an exception.
If I use UTC time it works as expected.
It seems I can read and store documents with a timezone offset just fine, I'm hoping this is just a minor tweak that needs to be done to the linq provider? 🤔
Code to reproduce (LastUpdated on Person is a DateTimeOffset):
Exception message:
Stack trace:
The text was updated successfully, but these errors were encountered: