Reputation: 8331
I am using EF6 and trying to use Code First with Migrations against a SQL DB.
Is it possible using a data annotation in my POCO class to specify that the default value of a Boolean or Bit field should be true?
I know I could modify the data migrations code to add it to the specific migration class but would like to avoid that.
Upvotes: 2
Views: 2756
Reputation: 1223
check this: How to set default value for POCO's in EF CF?
You can do this through Migration step.
public class Test
{
(...)
public bool TestProperty { get; set; }
(...)
}
public partial class AddTestClass : DbMigration
{
public override void Up()
{
CreateTable(
"Test",
c => new
{
(...)
TestProperty = c => c.Boolean(nullable: false, defaultValue: false)
(...)
})
(...)
}
public overide void Down()
{
// Commands for when Migration is brought down
}
}
`
Upvotes: 2