In Entity Framework Code First approach, how do you set a default value for a property in the POCO\'s EntityConfiguration class?
public class Person
{
pu
In the case where you want SQL Server to provide a default date the way you would accomplish this is, the important part is defaultValueSql: "GETDATE()" which will set the sql server default, not just evaluate to the time the script was run (i.e. DateTime.UtcNow)
public partial class AddPersonClass : DbMigration
{
public override void Up()
{
CreateTable(
"People",
c => new
{
Id = c.Int(nullable: false, identity: true),
Name = c.String(maxLength: 100),
CreatedOn = c.DateTime(nullable: false, defaultValueSql: "GETDATE()")
})
.PrimaryKey(t => t.Id);
}
public overide void Down()
{
// Commands for when Migration is brought down
}
}