Bug #87120 | EntityFrameworkCore MySQLDataReader throws exception with 0000-00-00 date | ||
---|---|---|---|
Submitted: | 19 Jul 2017 14:33 | Modified: | 6 Oct 2017 20:48 |
Reporter: | Thomas Wendt | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | Connector / NET | Severity: | S2 (Serious) |
Version: | 8.0.8-dmr | OS: | Any |
Assigned to: | Roberto Ezequiel Garcia Ballesteros | CPU Architecture: | Any |
Tags: | ConvertZeroDateTime, datetime, entityframework |
[19 Jul 2017 14:33]
Thomas Wendt
[19 Jul 2017 14:35]
Thomas Wendt
.NetCore Project to reproduce the issue
Attachment: MySQLTest.zip (application/zip, text), 2.14 KiB.
[29 Jul 2017 0:18]
Jonatan Bouillon
I had the same problem and the cause is because in the MySql.Data.EntityFrameworkCore.Storage.Internal MySQLDataReader the function look not to be the rigth one call. Right now it is using the GetMySqlDateTime(ordinal).GetDateTime() but this is not working with date format '0000-00-00'. You must use the following function instead. public override DateTime GetDateTime(int i) { IMySqlValue val = GetFieldValue(i, true); MySqlDateTime dt; if (val is MySqlDateTime) dt = (MySqlDateTime)val; else { // we need to do this because functions like date_add return string string s = GetString(i); dt = MySqlDateTime.Parse(s); } dt.TimezoneOffset = driver.timeZoneOffset; if (_connection.Settings.ConvertZeroDateTime && !dt.IsValidDateTime) return DateTime.MinValue; else return dt.GetDateTime(); } I have change it for the following and it works. Before : public override DateTime GetDateTime(int ordinal) => GetReader().GetMySqlDateTime(ordinal).GetDateTime(); After : public override DateTime GetDateTime(int ordinal) => GetReader().GetDateTime(ordinal); You must also add the ConvertZeroDateTime in the connexionstring.
[31 Jul 2017 15:49]
Chiranjeevi Battula
Hello Thomas, Thank you for the bug report. Verified based on internal discussion with dev's. Thanks, Chiranjeevi.
[6 Oct 2017 20:48]
Christine Cole
Posted by developer: Fixed as of the upcoming MySQL Connector/NET 6.10.4 release, and here's the changelog entry: Inserting a date of '0000-00-00' into a column when also setting Convert Zero Datetime=True in the connection string of a class that derives from DbContext produced an exception, instead of performing the expected conversion. Thank you for the bug report.