EntityFramework Code First FluentAPI DefaultValue in EF6.X

c# ef-code-first ef-fluent-api entity-framework

Question

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);
1
32
2/21/2015 8:57:51 PM

Popular Answer

Good news, code first now supports this. In the "Up()" method of the generated migration, specify a default with the following syntax:

AddColumn("[table name]", "[column name]", c => c.Boolean(nullable: false, defaultValue: false));

MSDN for "AddColumn" method

31
3/12/2014 9:06:08 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow