I want to create a DateTime field so that it will have a default GETDATE()
once it gets to the database. So I did this:
public class Specialty
{
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public DateTime? CreatedDate { get; set; }
// other properties not shown for brevity.
}
So I ran Add-Migration in the PM> console. It resulted in this (not all lines are shown) in the Up function:
AddColumn("dbo.Specialty", "CreatedDate", c => c.DateTime());
I understand that nullable of c.DateTime(...) is true by default, so I understand why it's not specified. BUT where is defaultValueSql: "GETDATE()"
?
I know I can put it in manually, but that seems to defeat the purpose of Add-Migration
and makes [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
useless. I know for a fact that defaultValueSql's default is not "GETDATE()" because it doesn't show up when I look at column properties in SQL Management Studio.
What's missing? Does the name "CreatedDate" violate an EF convention, then? Is there another library that I should have referenced besides System.ComponentModel.DataAnnotations.Schema
?