none
Allow Zero Datetime - MySql RRS feed

  • Question

  • Hi,

    I'm having some problems with mysql with a DateTime field. In it I have values like '0000-00-00 00:00:00' .

    I tried adding Allow Zero Datetime=true to the connection string but nothing seems to happen. Could there be another setting in EF4 that I could try ?

    • Moved by VMazurModerator Thursday, April 29, 2010 10:38 AM (From:ADO.NET Managed Providers)
    Wednesday, April 28, 2010 3:34 AM

Answers

  • Hi,

     

    In the end I found out that you also need to set Convert Zero Datetime=true; in the connection string. And the the MySql provider will return DateTime.Min.

    Thanks for the link on how to setup a new custom provider. It was really interesting ( even if it seems like it's a lot of work)

    • Marked as answer by sirrocco Tuesday, May 4, 2010 3:12 AM
    Tuesday, May 4, 2010 3:12 AM

All replies

  • I looked through the connector code - and from what I can see this is by design, which I don't really understand. The code is like this :

     

    /// <summary>Returns this value as a DateTime</summary>
    		public DateTime GetDateTime()
    		{
    			if (!IsValidDateTime)
    				throw new MySqlConversionException("Unable to convert MySQL date/time value to System.DateTime");
    
    			return new DateTime(year, month, day, hour, minute, second);
    		}

    So if it's 0 0 0 for any of (year, month, day) then it's not valid . But a bit lower in the class there's an explicit operator to DateTime that

    if (!IsValidDateTime)

    returns DateTime.Min which would be ideal.

     

    Is there any way I can tell EF4 which MySql connector dll to use ? I could just recompile the source.

    Wednesday, April 28, 2010 3:49 AM
  • Hello,

     

    Welcome to Data Platform forums!

     

    If you want to modify the third party EF provider and create a new provider, yes of course, we can let EF use our custom provider.   We need to first register the provider and change the entity connection string to load the custom provider.   For detail, please see the Configuration Providers section in this blog, http://blogs.msdn.com/jkowalski/archive/2009/06/11/tracing-and-caching-in-entity-framework-available-on-msdn-code-gallery.aspx.  

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, April 28, 2010 1:14 PM
    Moderator
  • Hi,

     

    In the end I found out that you also need to set Convert Zero Datetime=true; in the connection string. And the the MySql provider will return DateTime.Min.

    Thanks for the link on how to setup a new custom provider. It was really interesting ( even if it seems like it's a lot of work)

    • Marked as answer by sirrocco Tuesday, May 4, 2010 3:12 AM
    Tuesday, May 4, 2010 3:12 AM
  • Cool!  Glad to hear that!  

    Good day!


    Best Regards,
    Lingzhi Sun
    MSDN Subscriber Support
    in Forum
    If you have any feedback on our support, please contact
    msdnmg@microsoft.com.  


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, May 5, 2010 8:58 AM
    Moderator