Table T2 in SQL Server contains two columns:
Id INT NOT NULL CreateDate DateTime NOT NULL, default = (getdate())
Because it utilises (getdate()) by default, this line successfully adds the CreateDate value.
Insert T2 (Id) Values (1)
All is OK thus far. Using Entity Framework to enter a row but still wanting to utilise the default (
Due to the
, When using EF, I am unable to leave it empty or leave it out of the Insert statement. But I want the server/database side of SQL to provide the timestamp.
Is there a solution for this?
I was able to discover the solution because to squillman's a mention of another SO post.
You can do what I'm attempting to do by setting the StoreGeneratedPattern attribute in the EDMX diagram.
There are three options generated by a database.
Computed : The database generates a value when a row is inserted or updated. Identity : The database generates a value when a row is inserted. None : The database does not generate values.
EDIT: I had to modify Identity to Computed even though the image displays Identity. The Identity option only works if the row is Inserted, which is the cause. Any time the row is modified (other columns are updated), an error occurs. The default script is executed when using the Computed option with Insert and Updates (to other columns, default script does not run again).