How can I set the default value using EntityFramework Code First FluentAPI for bool property?
Something like:
Property(l => l.PropertyFlag).HasColumnType("bit").DefaultValue(1);
How can I set the default value using EntityFramework Code First FluentAPI for bool property?
Something like:
Property(l => l.PropertyFlag).HasColumnType("bit").DefaultValue(1);
Good news, code first now supports this. In the "Up()" method of the generated migration, specify a default with the following syntax:
MSDN for "AddColumn" method
Another option here is to override the default SqlServerMigrationSqlGenerator class with your own. You can then inject certain things you want to happen in the Generate method (for example, default values). The nice things with this is that you can also use this in other applications as it is pretty generic. Here is a good explanation on it.
Since EF doesn't have the functions I need, such as default values and unique key as foreign keys, we have to change the ORM from EF to NHibernate. It seems to me that NHibernate has more functions than EF 6.X.
I'm not sure about a fluent way, but you can simply set the property in a parameterless constructor...
Update
A quick google suggests it is not possible using the fluent api...
http://social.msdn.microsoft.com/Forums/en-US/ad854e28-02f5-451b-9000-c8bcb1355d0b/codefirst-ctp5-and-default-values?forum=adonetefx