Home
Options

Can't insert records with TIMESTAMP fields in MariaDB using MySQL (Pomelo) Provider

edited March 15

I'm having this issue using the MySQL (Pomelo) provider (latest version but tried older ones as well).
I'm using 10.1.48-MariaDB-0+deb9u2 as a database, and created a test table with only 3 fields:

Testtabel
- ID (INT - autogenerated)
- created_date_time (DATETIME)
- created_timestamp (TIMESTAMP)

and just execute the following code:

Testtabel.Add(new Testtabel(){
    CreatedDateTime = DateTime.Now,
    CreatedTimestamp = DateTime.Now
});
SaveChanges();

Sadly, the result is not what I would expect, as the created_timestamp field is empty:

What could be causing this? Is there a bug in LinqPad or in the provider? Am I doing something incredibly stupid or wrong?

Comments

  • Options

    I've tested adding the data using the same MySqlConnector library that Pomelo is using and everything seems to be working fine:

    using var connection = new MySqlConnection("Server=xxxx;User ID=xxxx;Password=xxxx;Database=xxxx");
    connection.Open();
    
    using (var cmd = new MySqlCommand())
    {
        cmd.Connection = connection;
        cmd.CommandText = "INSERT INTO testtabel_sync (created_date_time, created_timestamp) VALUES (@dt, @ts)";
        cmd.Parameters.AddWithValue("dt", DateTime.Now);
        cmd.Parameters.AddWithValue("ts", DateTime.Now);
        await cmd.ExecuteNonQueryAsync();
    }
    
    using var command = new MySqlCommand("SELECT * FROM testtabel_sync;", connection);
    using var reader = command.ExecuteReader();
    reader.Dump();
    

Sign In or Register to comment.