Timestamp issue with MySql connector 6.0 – 6.1 for Entity Framework

Standard

This is really a short post as to highlight an issue that I run into (and most will) when using MySql with Entity Framework employing the mysql connector net.

 

Scenario

I work mostly on my laptop which has mysql connector 6.0.4 installed. Using the connector in conjunction with EF v1 generated my domain object with timestamp fields mapping from a binary in my conceptual schema to timestamp in my physical schema.  Everything worked just fine till I deployed to my production machine and realized I didn’t have mysql connector installed on my production server. So…I did what most will do, download the connect but installed the latest version (v6.1). After deploying my app to the server, the unexpected happened. My app was broken. The error message indicated that Edm.binary was not compatible to mysql.timestamp. OK, I was stumped. The app works just fine on my my laptop why not on my server.

 

Solution

After a couple of hours using process of elimination, I realized that using version 6.1 of the connector sets your mapping for timestamp from Edm.DateTimeOffset(conceptual schema) to timestamp (physical schema)which worked fine but version 6.0.4 of the connector sets your mapping for timestamp from Edm.binary(conceptual schema) to timestamp (physical schema) which also works as well. DateTimeOffset is a type specific to Sql server so the best option for me was to stay with 6.0.1  (using binary) which is generic and can be used with other db’s if ever need.

Advertisements

3 thoughts on “Timestamp issue with MySql connector 6.0 – 6.1 for Entity Framework

  1. bobotha

    hi,
    thanks for your post. your scenario looks similar with mine,.
    i’m using mysql database with .net ria services as the framework. so i have a datamodel.edmx.
    and i have a field with timestamp in my database. when i try to call the entity in the datamodel, it returns an error:

    “error 2019: member mapping specified is not valid. the type ‘edm.datetime[nullable=false,defaultvalue=,precision=]” of member ‘updateindb’ in type ‘pulsamodel.inbox’ is not compatible with ‘mysql.timestamp[nullable=false,defaultvalue=,precision=0]’ of member ”updateindb’ in type ‘pulsamodel.inbox'”

    i’m using mysql server 5.1.3, and mysql-connector-6.2.4.
    is it okay?

    thanks so much for your rensponse.

    -Botha-

    • emmanuelbuah

      It really depends on what version of EF and MySQL connector you are using. The last time I used mysql connector was with version 6.1 per my post. The best thing to do is verify/double check the data-type a timestamp in MySQL connector 6.2.4. If you are using the same connector version for both the model generation and data manipulation, then you shouldn’t have a problem. Let me know what you dig out.

      • bobotha

        finally, i change the timestamp data type to datetime, and add the triggers to replace current_timestamp function. and it works well..
        thanks so much. 😉

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s