From the docs sample: https://ef.readthedocs.io/en/latest/modeling/relational/default-values.html
``` c#
class MyContext : DbContext
{
public DbSet
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Blog>()
.Property(b => b.Created)
.HasDefaultValueSql("CURRENT_TIMESTAMP");
}
}
public class Blog
{
public int BlogId { get; set; }
public string Url { get; set; }
public DateTime Created { get; set; }
}
```
The DB default in MySql is correct, but when saving this entity, without setting the Created property, it defaults to the DateTime Min of '0001-01-01 00:00:00'. If you do an insert directly in MySql it obviously works fine.
I would assume the correct behavior would be to read back the value or use in the sql statment 'UTC_TIMESTAMP()'.
I can workaround by setting date in code, but would be good to understand if this is just bug or not.
DotNet Core 1.0 RTM
MySQL version: 5.7
Pomelo.EntityFrameworkCore.MySql version: 1.0.0-prerelease-20160803
Hi @greghroberts. DateTime is a value type in .net. The default value is going to be default(DateTime) if you did not specify a default value, is '0001-01-01 00:00:00'.
You can also define a default value in your model:
c#
public DateTime Created { get; set; } = DateTime.Now;
I understand it's a value type. My question is more on if you plan on making DefaultValues work as per the EF docs. The attached example and link do not work as designed.
@greghroberts Confirmed a bug, thanks for reporting this issue, we will fix it in some hours.
@greghroberts Thanks again. We have fixed this bug, and we will release this new version later.
Awesome thanks!
Most helpful comment
Hi @greghroberts. DateTime is a value type in .net. The default value is going to be default(DateTime) if you did not specify a default value, is '0001-01-01 00:00:00'.
You can also define a default value in your model:
c# public DateTime Created { get; set; } = DateTime.Now;