How do I set a default value on a bit field using Entity Framework Core code-first?

asp.net-core c# entity-framework-core

Question

Here is my code:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<Skill>()
        .Property(s => s.FlagTrainedOnly)
        .HasDefaultValue(false);
}

And the error I get:

Error CS1061
'PropertyBuilder' does not contain a definition for 'HasDefaultValue' and no extension method 'HasDefaultValue' accepting a first argument of type 'PropertyBuilder' could be found (are you missing a using directive or an assembly reference?)

1
3
5/10/2017 4:49:04 AM

Popular Answer

Make sure you've got

using Microsoft.EntityFrameworkCore;

at the top and then try putting it on one line like this

protected override void OnModelCreating(ModelBuilder modelBuilder) {
    modelBuilder.Entity<Skill>().Property(p => p.FlagTrainedOnly).HasDefaultValue(false);
}

Then put it on multiple lines. I think sometimes it needs to be reminded that the dot extensions exist.

1
11/17/2017 1:59:17 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