Friday, August 30, 2013

Default GETDATE() contraint for column and LINQ in Entity Framework 5.0

If we have a datetime column that we want to set the default to the current date and time we can use

alter table MyTable add constraint DefGetDate DEFAULT GETDATE() FOR myColumn


In edmx, select the column from the entity and set the StoreGeneratedPatern to Computed or Identity.

The available values for StoreGeneratedPatern are:


  • None A value indicating that it is not a server generated property. This is the default value.
  • Identity A value is generated on insert and remains unchanged on update.
  • Computed A value is generated on both insert and update.

The MSDN page regarding this is http://msdn.microsoft.com/en-us/library/system.data.metadata.edm.storegeneratedpattern.aspx

No comments:

Post a Comment