Accessing a NULL Timestamp Column Using a MySQL.NET Connector

We use the MySQL.NET Connector 6.7.4 to access the MySQL database using Entity Framework 5.0 in .NET. After upgrading to version 6.7.4, we ran into problems with the timestamp column where NULL is allowed. We can save values โ€‹โ€‹without problems (i.e., the column will be updated correctly in db), but whenever we retrieve an object corresponding to a row in the database, the property corresponding to this column always returns null. We tried to change the precision of the column in the edmx file, but that didn't change the behavior at all. Has anyone else experienced this issue? Is there any known workaround besides downgrading to an older version of MySQL.NET Connector?

+4
source share
2 answers

Have you tried adding 'convert zero datetime = true' to your connection string? This will convert the values โ€‹โ€‹of 0000-00-00 to DateTime.MinValue.

see http://dev.mysql.com/doc/refman/5.5/en/connector-net-connection-options.html and also http://dev.mysql.com/doc/refman/5.0/en/connector- net-programming-datetime.html

for more information

+1
source

What happens if you use the IFNULL function? I.e.

SELECT IFNULL(mytimestamp,'0001-01-01 00:00:00') FROM mytable 

This should return a column that is not null and always has a value. The return value must be either the value of the mytimestamp column or "0001-01-01 00:00:00" (your default value).

+1
source

Source: https://habr.com/ru/post/1497225/


All Articles