-
Notifications
You must be signed in to change notification settings - Fork 335
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
Read DATE
as DateOnly
value
#1451
Comments
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. |
Another existing request for |
@iamcarbon Created #1454 for this idea. Note that |
Hello @bgrainger, I'm looking for a good first issue to contribute. Can I work on this one? Do you have any additional tips regarding the implementation? Should the TIME type also be covered or only DATE for now? |
Related issue for Npgsql: npgsql/npgsql#5328 |
@BogdanYarotsky #375 is probably the best "first issue", as there are existing examples and the code should be fairly straightforward. (For this particular issue, the design isn't finalised yet, particularly around a connection string option to control it.) |
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: