For example, most of my entities have DateCreated and DateModified fields. The defaults to these are set to GetUtcDate() in SQL Server.
If I try and create an entity and don’t set these values, I get an exception saying it can’t run the SQL insert because the date value is out of range. Makes sense because C# default dates are 1/1/0001 while SQL Server’s minimum date is 1/1/1753.
So is there a way I can tell EF to either use the SQL Server default values, or to NOT try and insert columns which have not been set?
You must set
StoreGeneratedPatternfor those properties toIdentityforDateCreatedandComputedforDataModified. It is available in designer. Once you do that you cannot modify those values in your application – only database can set those properties. I wrote about this some article because this feature had bug before VS2010 SP1 but there are reports that it still doesn’t work sometimes.