jonwagner / Insight.Database

Fast, lightweight .NET micro-ORM
Other
856 stars 145 forks source link

How can I select a DateTime as UTC - not as kind "Unspecified"? #494

Closed elandev closed 4 months ago

elandev commented 1 year ago

Describe the question

I am inserting a row into the database where the DateTime property value is in UTC.

When I query the data back from the database it is not returned as UTC, but as the kind "Unspecified".

This causes other issues when doing datetime and interval comparisons. Thus, I have to manually convert the datetimes from the database to UTC, before doing any such comparisons.

Is there a way, possibly through a property attribute, to indicate that the DateTime should be of the kind UTC?

Steps to reproduce

  1. Load the attached project with Visual Studio 2022.
  2. Set up MariaDB as the database (10.11.2-MariaDB).
  3. Edit the server, database name and credentials for the connection string.
  4. Restore Nuget packages and build the solution.
  5. Run the project.

Look at the console output and you will see:

DateTime Inserted: 2023-03-25 17:38:26Z Kind=Utc
DateTime Returned: 2023-03-25 17:38:26Z Kind=Unspecified
DateTime Returned: 2023-03-25 17:38:26Z Kind=Unspecified

TestMySqlDateTime.zip

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

elandev commented 1 year ago

Is there a solution to this?

stale[bot] commented 5 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

jonwagner commented 4 months ago

Unfortunately, we can't accept project zip files as reproduction cases. Please paste sufficient code to reproduce here, or submit a PR with a failing test case.