Entity Framework Code First CTP4 Default Column Values?

Lukasz picture Lukasz · Oct 27, 2010 · Viewed 8.9k times · Source

I have been looking into Code First with Entity Framework CTP4 and you can use the ModelBuilder to build up your table columns. Is there a way to set the default value for a column in the database using the ModelBuilder or some other mechanism?

Thank You!

Answer

Korayem picture Korayem · Feb 17, 2011

I am using the constructor to set the default values. Never failed me

public class Activity
{
    [Required]
    public DateTime AddedDate { get; set; }

    public Activity()
    {
        AddedDate = DateTime.Now;
    }
}