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!
Just open your model, right click on the column you want to set a default for, choose properties, and you will see a "DefaultValue" field. Just fill that out and save. It will set up the code for you.
edmx viewer select an entity -> go the column -> properties -> Default Value. Add the default value for the column in it and that's it.
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;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With