Skip to content
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

MySqlDataAdapter.Fill() does not use DateOnly type for a db column of type Date #1836

Closed
Germs2004 opened this issue Feb 2, 2024 · 3 comments

Comments

@Germs2004
Copy link

Does this issue with MySqlConnector.MySqlDataAdapter belong here or some other project?

Steps to reproduce

// setup:
// create a MariaDB table named MyTable
// add a column of type "Date" named "MyDateColumn"
// add a row with a date value in MyDateColumn
using (MySqlCommand cmd = new("SELECT * FROM MyTable;", (MySqlConnection)connection))
{    
	using (MySqlConnector.MySqlDataAdapter adapter = new(cmd))
	{
		DataSet resultsDataSet = new();
		adapter.Fill(resultsDataSet);

		bool isCorrectType = resultsDataSet.Tables[0].Columns["MyDateColumn"].DataType == typeof(DateOnly);
	}
}

The issue

isCorrectType == false.

The data in the database has MySql type Date, so the Fill() command should create a DataColumn of C# type DateOnly. Instead, it creates a DataColumn of C# type DateTime.

Further technical details

MySQL version: 11.2.2-MariaDB
Operating system: Windows 10 Pro 22H2
Pomelo.EntityFrameworkCore.MySql version: 8.0.0-beta.2
Microsoft.AspNetCore.App version: net8.0

@lauxjpn
Copy link
Collaborator

lauxjpn commented Feb 13, 2024

@Germs2004 Please report your issue on the MySqlConnector repo, which is the underlying ADO.NET library that Pomelo uses to access MySQL compatible databases. Thanks!

/cc @bgrainger

@bgrainger
Copy link
Collaborator

For backwards compatibility, MySqlDataReader, MySqlDataAdapter, etc. all return DATE columns as DateTime values, even though DateOnly would be a "better" CLR type. As noted in mysql-net/MySqlConnector#1231 (comment) this could be changed, but would need to be an opt-in behavior triggered by a connection string option. (There are currently no plans to implement this; as a workaround, C# clients can extract a DateOnly value from a DateTime value.)

@Germs2004
Copy link
Author

Germs2004 commented Feb 14, 2024

Thank you for linking to the correct project. For anyone interested, here is the issue there: mysql-net/MySqlConnector#1451

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

No branches or pull requests

3 participants