1

I have the following table in my MySQL database :

CREATE TABLE IF NOT EXISTS Benutzer (
Id INTEGER PRIMARY KEY AUTO_INCREMENT,
Login VARCHAR(20) NOT NULL,
Nachname VARCHAR(50) NOT NULL,
Vorname VARCHAR(50) NOT NULL,
Timestamp TIMESTAMP DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP
)

In my Visual Studio 2010-edmx the field Timestamp has the following atrributes:

StoreGeneratedPattern: Computed
Type: DateTime

On inserting a new record into the table I get the following exception:

Devart.Data.MySql.MySqlException: Incorrect datetime value: '0001-01-01 00:00:00' for column 'Timestamp' at row 1.

I need the Timestamp-field to handle concurrency issues.

Version of Devart.Data.MySql.Entity is 6.0.86.0. Im am using Visual Studio 2010 and .Net Runtime 3.5 Sp1.

Help is appreciated.

shepard1
  • 55
  • 2
  • 7

1 Answers1

1

Maybe you should IGNORE update this DateTime field by EntityFramework. Just let database handle its value update automatically.

It seems EntityFramework give a default value to DateTime field which is "0001-01-01 00:00:00", it's the default behavior of .NET.

    [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
    public DateTimeOffset CreateDate { get; set; }

Use above annotation will tell EF to ignore the CreateDate when make changes to the entity.

ehe888
  • 158
  • 2
  • 6