Bug #73788 Unable to use DateTimeOffset in code-first EF model with MySQL Connector for .NE
Submitted: 3 Sep 2014 4:11 Modified: 16 Dec 2014 10:13
Reporter: J Crim Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:6.8.3.2, 6.9.5 OS:Any
Assigned to: CPU Architecture:Any
Tags: DateTimeOffset, EF

[3 Sep 2014 4:11] J Crim
Description:
MySQL Server version 5.6.20 Community

I'm unable to use properties of type DateTimeOffset in a MySQL + EF DbContext - the feature appears to be partly implemented, but never tested.

The workaround is to use DateTime + a separate timezone offset; and that's doable in many cases, but this specific bug causes problems with the Web API OData v4 implementation - which insists that DateTime should not be supported, only DateTimeOffset is.

I've provided an xunit test case with 2 failures that should go away when this issue is fixed.

How to repeat:
This code reproduces the bug - I'll also attach the solution to the issue:

// // -----------------------------------------------------------------------

using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Xml;
using MySql.Data.Entity;
using Xunit;

namespace MySqlConnNetBugs
{

	/// <summary>
	/// Provides a test to show how DateTimeOffset is broken in MySQL Connector.NET v6.8.3.2
	/// </summary>
	public sealed class DateTimeOffsetTests
	{
		/// <summary>
		/// Exercises some of the code called when migrations are run, to show where the breaking point is.
		/// </summary>
		/// <remarks>
		/// To run migrations from package manager console in visual studio:
		///   PM> enable-migrations -EnableAutomaticMigrations -Verbose
		///   PM> update-database -Script -Verbose
		/// </remarks>
		[Fact]
		public void TestGenerateSchema()
		{

			// When migrations are run, an EDMX model is generated.  This does the same, showing where the break is:
			using (var xmlWriter = new XmlTextWriter(Console.Out))
			{
				EdmxWriter.WriteEdmx(new MyDb(), xmlWriter);
			}

		}

		[Fact]
		public void ConnectionOpens()
		{
			bool anyRowsPresent;
			using (var db = new MyDb())
			{
				anyRowsPresent = db.MyEntities.Any();
			}
		}

	}

	public class MyEntity
	{
		public int Id { get; set; }
		public DateTimeOffset DateTimeOffset { get; set; }

	}

	[DbConfigurationType(typeof(MySqlEFConfiguration))]
	public class MyDb : DbContext
	{
		public DbSet<MyEntity> MyEntities { get; set; }
	}

}
[3 Sep 2014 4:15] J Crim
Zip file containing the solution with xunit test cases.

Attachment: MySqlConnNetBugs.zip (application/x-zip-compressed, text), 9.35 KiB.

[16 Dec 2014 10:13] Chiranjeevi Battula
Hello J Crim,

Thank you for the bug report.
Verified this behavior on Visual Studio 2013 (C#.Net) with  MySQL Connector/Net 6.9.5.

Thanks,
Chiranjeevi.
[8 Jul 2015 20:00] Eduardo Rivera
I have a problem and i think is related to this bug.

My Mysql-databse has a table with a timestamp column that is mapped to a System.DateTime, and it should be mapped to DateTimeOffset type. How can i handle this?. 

Thanks.
[8 Jul 2015 20:01] Eduardo Rivera
By the way, i have Connector 6.9.6.