我有一個類,看起來像這樣:實體框架遷移不包括默認值數據註解(EF5RC)
[Table("Subscribers", Schema = "gligoran")]
public class Subscriber
{
[Key]
public string Email { get; set; }
[Required]
[DefaultValue(true)]
public bool Enabled { get; set; }
}
當創建遷移到包括這個類,我得到:
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");
}
}
我想了Enabled
線看起來像這樣:
Enabled = c.Boolean(nullable: false, defaultValue: true),
我當然能做到這一點我自己,b我只是問是否有辦法讓Entity Framework自動執行。
我正在使用最新的Entity Framework 5 RC(5.0.0-rc.net40)。
我想手動是唯一的。儘管如此,感謝UserVoice鏈接。我對他們有幾個想法。 – gligoran 2012-07-19 20:40:13
其實MS今天發佈了[EF作爲開源](http://entityframework.codeplex.com/),所以你甚至可以自己試試;) – 2012-07-19 20:43:54
不錯!我前幾天正在尋找它,並得出結論說它不是開放的。我喜歡新的(ish)微軟開放政策。 – gligoran 2012-07-19 21:31:00