czetsuya
czetsuya

Reputation: 5093

Entity Framework Code First default valut for bit datatype

Using EntityFramework codefirst's latest version (4.3), I've created a table with column Enabled(bit). Then I've found out that it has a default value of false, can I set the default value to true?

I've found something weird when I renamed the column to Disabled the default value becomes null.

Upvotes: 1

Views: 8365

Answers (1)

Eranga
Eranga

Reputation: 32447

You can initialize Enabled to true in the constructor

public class Foo
{
    public Foo()
    {
        Enabled = true;
    }

    public bool Enabled { get; set; }
}

Your Disabled column must a a nullable column. Hence its default value is null.

Upvotes: 6

Related Questions