1

I'd like to add some properties to a entity to a model, but that property doesn't make any changes in the database nor in a migration script.

When I add this:

    public test test1 { get; set; }

    public enum test { asasas, asdasdasd };

I get an empty migration

    public override void Up()
    {
    }

    public override void Down()
    {
    }

But when i add:

    public String test1 { get; set; }

    public enum test { asasas, asdasdasd };

I get the expected migration

    public override void Up()
    {
        AddColumn("dbo.SpiderBatches", "test1", c => c.String());
    }

    public override void Down()
    {
        DropColumn("dbo.SpiderBatches", "test1");
    }

Because the second change does make a correct migration I can assume that the class/context are correctly setup and are working. So the error must be in the enum.

Can anyone help me further?

4

2 回答 2

1

仅当您面向 .NET 4.5 时才支持枚举,4.0 不支持它

于 2012-09-28T08:25:26.720 回答
0

上面对于 .net 4.5 的答案很好,但是如果您需要像我一样支持 .net 4.0,那么您可以将要在模型上表示的枚举属性包含为 int。

两件事情 -

1,按照下面对您的值进行硬编码,以避免在 .cs 文件中更改它们的顺序而破坏您的参照完整性

public enum MyEnum
{
    FirstProperty = 1,
    AskUser = 2,
    IgnoreLine = 3,
    ImportPrice = 4,
    Undecided = 5
}

2 - 当您保存回数据库时,您需要在保存之前将枚举转换为 int,例如

MyEntity.PsuedoEnumProperty = (int)FirstProperty
于 2014-07-15T13:44:59.883 回答