Entity Framework Migrations don't include DefaultValue data annotation (EF5RC)

c#, entity-framework-5, entity-framework-migrations

Solution

EF doesn't use `DefaultValue` attribute at all = it is not part of the model so migrations don't see it. You can propose support of this annotation on Data UserVoice.

Problem

I have a class that looks like this: ``` [Table("Subscribers", Schema = "gligoran")] public class Subscriber { [Key] public string Email { get; set; } [Required] [DefaultValue(true)] public bool Enabled { get; set; } } ``` When creating a migration to include this class I get: ``` public partial class AddSubscriberClass : DbMigration { public override void Up() { CreateTable( "gligoran.Subscribers", c => new { Email = c.String(nullable: false, maxLength: 128), Enabled = c.Boolean(nullable: false), }) .PrimaryKey(t => t.Email); } public override void Down() { DropTable("gligoran.Subscribers"); } } ``` I'd like the `Enabled` line to look like this: ``` Enabled = c.Boolean(nullable: false, defaultValue: true), ``` Of course I can do this myself, but I'm just asking if there's a way to make Entity Framework do it automatically. I'm using the latest Entity Framework 5 RC (5.0.0-rc.net40).

Original source