实体框架迁移忽略了一些枚举

时间:2013-04-16 16:07:24

标签: entity-framework enums ef-migrations

首先,我们使用的是.NET 4.5,所以这应该不是问题。

我有六个带枚举属性的类,但是当我创建迁移时,由于某种原因它忽略了两个类的枚举属性,而忽略了其他类!

例如,这个类:

public class CreditCardForeignUsage : EntityBase
{
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public override int Id { get; set; }

    public virtual CreditCard CreditCard { get; set; }
    public int CreditCardId { get; set; }

    public bool? Active { get; set; }
    public ForeignUsageNetwork? Network { get; set; }
    public ForeignUsageLocation? Location { get; set; }
    public decimal? Percent { get; set; }
    public bool? ManuallyAdded { get; set; }
}

生成以下迁移代码(一切正常):

            CreateTable(
            "dbo.CreditCardForeignUsage",
            c => new
                {
                    Id = c.Int(nullable: false, identity: true),
                    CreditCardId = c.Int(nullable: false),
                    Active = c.Boolean(),
                    Network = c.Int(),
                    Location = c.Int(),
                    Percent = c.Decimal(precision: 18, scale: 2),
                    ManuallyAdded = c.Boolean(),
                    Timestamp = c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"),
                    Created = c.DateTime(nullable: false),
                })
            .PrimaryKey(t => t.Id)
            .ForeignKey("dbo.CreditCard", t => t.CreditCardId)
            .Index(t => t.CreditCardId);

但是这堂课:

public class CreditCardRate : EntityBase
{
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public override int Id { get; set; }

    public virtual CreditCard CreditCard { get; set; }
    public int CreditCardId { get; set; }

    public bool? Active { get; set; }
    public RateType? RateType { get; set; }
    public int? MinBalance { get; set; }
    public int? MaxBalance { get; set; }
    public int? RatePeriod { get; set; }
    public DateTime? RateDate { get; set; }
    public decimal? MonthlyRate { get; set; }
    public YearlyRateType? YearlyRateType { get; set; }
    public decimal? YearlyRate { get; set; }
    public bool? ManuallyAdded { get; set; }
}

生成此内容(缺少RateType和YearlyRateType):

            CreateTable(
            "dbo.CreditCardRate",
            c => new
                {
                    Id = c.Int(nullable: false, identity: true),
                    CreditCardId = c.Int(nullable: false),
                    Active = c.Boolean(),
                    MinBalance = c.Int(),
                    MaxBalance = c.Int(),
                    RatePeriod = c.Int(),
                    RateDate = c.DateTime(),
                    MonthlyRate = c.Decimal(precision: 18, scale: 2),
                    YearlyRate = c.Decimal(precision: 18, scale: 2),
                    ManuallyAdded = c.Boolean(),
                    Timestamp = c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"),
                    Created = c.DateTime(nullable: false),
                })
            .PrimaryKey(t => t.Id)
            .ForeignKey("dbo.CreditCard", t => t.CreditCardId)
            .Index(t => t.CreditCardId);

有什么想法吗?这是某种错误吗?

修改

枚举声明如下:

namespace CE.Core.Portal.DTOs.CreditCards
{
    public enum RateType
    {
        StandardDirectDebit = 1,
        StandardPurchases = 2,
        StandardCash = 3,
        StandardOther = 4,
        IntroPurchases = 5,
        BalanceTransfer = 6,
    }
}

0 个答案:

没有答案
相关问题