Skip to content

Read DATE as DateOnly value #1451

Open
Open
@bgrainger

Description

For backwards-compatibility reasons, MySqlDataReader.GetValue will return a DateTime object for DATE columns, even though this could be represented by a .NET DateOnly struct.

For users who want a DateOnly, there are two simple workarounds:

  • MySqlDataReader.GetFieldValue<DateOnly>
  • MySqlDataReader.GetDateOnly

However, there may be cases such as PomeloFoundation/Pomelo.EntityFrameworkCore.MySql#1836 where it would be useful for the "natural" type of the column (retrieved by GetValue) to be DateOnly so no explicit conversion has to take place.

Since there is already a connection string option (AllowZeroDateTime) that causes GetValue to return MySqlDateTime (instead of DateTime), it's possible that a new connection string option could be introduced that switches the behavior of GetValue for DATE columns to return DateOnly. (Perhaps over time this could even become the default behavior and users would have to opt out of the new behavior instead of opting in.)

We could also consider returning TIME columns as a TimeOnly type instead of TimeSpan, but that would only work if the user was deliberately limiting values stored in that column to the range 00:00:00 to 23:59:59.9999999 instead of the full range of the TIME type, which is -838:59:59.000000 to 838:59:59.000000. This seems like it would always need to be an opt-in feature.

See also #963 (comment).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions