首先,我们使用的是 .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,
}
}