-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Allow specifying a default DateTimeKind #12994
Comments
Following other peoples suggestions (ModelBuilderExtension etc) in both #4711 and #10784, I decided to go ahead with:
Allows you to specify the default in the DbContext:
|
Duplicate of #10784? |
This solution works very well, except if you have a not mapped property on a data model. `// note that entityType.GetProperties() will throw an exception, so we have to use reflection foreach (var property in properties)` |
This is related to #4711 and #10784, basically a follow-up issue based on a comment by @rmja:
Usually, when you are designing a database, you have the full control over how dates might be stored inside of it. So regardless of whether your database supports storing the timeszone with the
DateTime
or not, it’s not uncommon to decide on a fixed timezone for all dates inside of a database. Usually, and that is also the general recommendation on this topic, this would be UTC.It would be really nice to be able to set up a default handling for the
DateTimeKind
. For example, a good and flexible rule could be this: If the kind is unspecified, interpret it as a UTC DateTime; otherwise convert it into a UTC DateTime, taking its kind into account.I’m currently doing this with a value converter like this:
This works pretty well but having to add this on every single DateTime property is really tedious. Of course, this particular solution will become obsolete when configuring a value converter globally for a property type becomes possible with (maybe) 3.0. But regardless of that, I think it would be worth to consider adding support for date time kinds in general, that is independent of value converters.
What do you think? Am I ignoring missing use cases that would break such a default, or would implementing this separately from default value converters be too complicated?
The text was updated successfully, but these errors were encountered: