I think you can do this using StoreGeneratedPattern = Identity (set in the model constructor properties window).
I would not have guessed that this would be how to do it, but, trying to figure it out, I noticed that some of my date columns no longer correspond to CURRENT_TIMESTAMP() , and some do not. Checking the model, I see that the only difference between the two columns besides the name is that the default value StoreGeneratedPattern set to Identity .
I would not expect this to be so, but reading the description, it makes sense:
Determines whether the corresponding column in the database is automatically generated during insert and update operations.
Also, while this makes the database column the default “now”, I think it does not actually set the DateTime.Now property to POCO. This was not a problem for me, because I have a customized .tt file that already automatically sets all my date columns to DateTime.Now (it’s actually easy to change the .tt file yourself, especially if you have ReSharper and get the syntax highlighting plugin (newer versions of VS may already syntactically highlight .tt files, not sure.))
The problem is for me: how do I get the default database column so that existing queries that omitted this column still work? And the above setup worked for this.
I have not tested it yet, but it is also possible that setting this will interfere with setting your own explicit value. (I just came across this, primarily because EF6 Database First wrote this model for me.)
Dave Cousineau Apr 17 '17 at 1:36 on 2017-04-17 01:36
source share