I've followed the examples like accepted here: Possible to default DateTime field to GETDATE() with Entity Framework Migrations?
In Sql server, the "Default Binding or Value" is now getting set to ('1900-01-01T00:00:00.000'), but not to GetDate() as I would expect.
public partial class InitialCreate : DbMigration
{
public override void Up()
{
AddColumn("dbo.UserWordsModels", "DateAdded", c => c.DateTime(defaultValueSql: "GETDATE()"));
}
public override void Down()
{
DropColumn("dbo.UserWordsModels", "DateAdded");
}
}
In the Model:
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public DateTime DateAdded { get; set; }
One thing I may have different is I set this so all DateTime fields are DateTime2
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Properties<DateTime>().Configure(c => c.HasColumnType("datetime2"));}