Hmm ... if you use EF6, it's actually a lot easier than you think. Just open your model, right-click on the column for which you want to set the default value, select the properties, and you will see the "DefaultValue" field. Just fill it in and save. He will set up a code for you.
The problem with some other solutions is that although they may work initially, as soon as you rebuild the model, it will throw out any custom code that you insert into the machine file.
So, under the hood, the user interface works by adding an additional property to the edmx file:
<EntityType Name="Thingy"> <Property Name="Iteration" Type="Int32" Nullable="false" **DefaultValue="1"** />
And adding the necessary code to the constructor:
public Thingy() { this.Iteration = 1;
Acorndog Mar 08 '17 at 19:45 2017-03-08 19:45
source share