实体框架迁移不包括默认值数据注解(EF5RC) [英] Entity Framework Migrations don't include DefaultValue data annotation (EF5RC)

查看:186
本文介绍了实体框架迁移不包括默认值数据注解(EF5RC)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类,看起来像这样:

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");
    }
}



我想在启用行看起来是这样的:

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.

我使用的是最新的实体框架5 RC(5.0.0-rc.net40)。

I'm using the latest Entity Framework 5 RC (5.0.0-rc.net40).

推荐答案

EF不使用默认值在所有的属性=这不是模型,使迁移的一部分看不出来。您可以在数据UserVoice的提出支持这一注释。

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.

这篇关于实体框架迁移不包括默认值数据注解(EF5RC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆