Default Values

Feb 28, 2015 at 6:57 PM
Is there any way to configure default values for entities?

Reagards,
Coordinator
Feb 28, 2015 at 7:23 PM
do you mean defaults for columns in DB? - these are supported, but I would not recommend using them unless you have to... they are quite tricky... If you mean defaults for property values in new entities - it is always null or default value for type (0). I recommend creating extension methods for creating new entities (see BookExtensions.cs in example) NewBook method - these serve as constructors for entities. Inside this method you can set (default) values for properties explicitly, and never worry about them anymore
Mar 1, 2015 at 4:01 PM
I mean default database values, like all the int's and decimal can have 0 as default for cases when records are inserted using external sources

Regards.
Coordinator
Mar 1, 2015 at 4:14 PM
Use Column attribute on property, with Default value assigned - just a string:

[Column(Default="1")]
int Foo {get;set;}

Although again, I found using the defaults to be quite tricky, even with MS SQL, mostly when it comes to updating db schema. So you might into some bumps there.