If I understand correctly mysql transforms into datetime(6) which I do not want to have I have a datetime(6) that I would like to change to datetime but I can't change it If someone has the right syntax, or another method ?
You have the declaration here of in my model
[DataType(DataType.DateTime)]
public DateTime? CreationDate { get; set; }
the result of mysql
--------------- -------------- ------ ----- --------- ----------------
| Field | Type | Null | Key | Default | Extra |
--------------- -------------- ------ ----- --------- ----------------
| creation_date | datetime(6) | YES | | NULL | |
CodePudding user response:
I believe you are mapping to the wrong field name CreationDate
vs creation_date
.
Try
public DateTime? creation_date { get; set; }
CodePudding user response:
The problem is that CreationDate
is different from the column name in database (creation_date
).
You have to tell EF that it should look for that name by adding an attribute:
Add this to your model:
using System.ComponentModel.DataAnnotations.Schema;
[DataType(DataType.DateTime)]
[Column(name: "creation_date")]
public DateTime? CreationDate { get; set; }
Then it should work.