You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Would it make sense to add a similar option to read JSON columns as byte[] (instead of a string)? This would allow the column to be bound to a JsonObject / JsonElement without additional conversions / allocations.
@iamcarbon Created #1454 for this idea. Note that MySqlDataReader.GetStream provides a Stream over the existing in-memory data without allocating a new byte[] (although it does of course allocate a Stream object).
For backwards-compatibility reasons,
MySqlDataReader.GetValue
will return aDateTime
object forDATE
columns, even though this could be represented by a .NETDateOnly
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 beDateOnly
so no explicit conversion has to take place.Since there is already a connection string option (
AllowZeroDateTime
) that causesGetValue
to returnMySqlDateTime
(instead ofDateTime
), it's possible that a new connection string option could be introduced that switches the behavior ofGetValue
forDATE
columns to returnDateOnly
. (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 aTimeOnly
type instead ofTimeSpan
, but that would only work if the user was deliberately limiting values stored in that column to the range00:00:00
to23:59:59.9999999
instead of the full range of theTIME
type, which is-838:59:59.000000
to838:59:59.000000
. This seems like it would always need to be an opt-in feature.See also #963 (comment).
The text was updated successfully, but these errors were encountered: