Entity framework 忽略某些枚举的实体框架迁移
首先,我们使用的是.NET4.5,所以这不应该是个问题 我有六个具有枚举属性的类,但是当我创建迁移时,出于某种原因,它忽略了其中两个类的枚举属性,而忽略了其他类的枚举属性 例如,该类:Entity framework 忽略某些枚举的实体框架迁移,entity-framework,enums,entity-framework-migrations,Entity Framework,Enums,Entity Framework Migrations,首先,我们使用的是.NET4.5,所以这不应该是个问题 我有六个具有枚举属性的类,但是当我创建迁移时,出于某种原因,它忽略了其中两个类的枚举属性,而忽略了其他类的枚举属性 例如,该类: public class CreditCardForeignUsage : EntityBase { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public override int Id { get; set; } pu
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; }
}
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; }
}
生成以下迁移代码(一切正常):
但这一类:
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; }
}
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):
有什么想法吗?这是某种错误吗
编辑
枚举声明如下:
namespace CE.Core.Portal.DTOs.CreditCards
{
public enum RateType
{
StandardDirectDebit = 1,
StandardPurchases = 2,
StandardCash = 3,
StandardOther = 4,
IntroPurchases = 5,
BalanceTransfer = 6,
}
}
枚举是否被忽略嵌套枚举(即,它们是否位于其他类型(类)中)?这些枚举类型的底层类型是什么?你能说明它们是如何定义的吗?不,它们都在命名空间中公开声明。我只是注意到我们使用EF 4.0和.Net 4.5。尽管这仍然不能真正解释为什么它在某些类上工作,而在其他类上不工作。首先,我们使用的是.Net 4.5,所以这不应该这是一个问题。考虑到对枚举的支持是在EF5中添加的,而不是在.NET Framework 4.5中添加的,您可能需要重新考虑这将是一个多大的问题。实际上,我收回这一点,我们正在使用EF 5。(对不起,我正在查看运行时版本:P)@ta.speot.is-枚举是在.NET Framework中的EF5组件中添加的,因此您必须使用.NET Framework 4.5才能将枚举与EF一起使用。EF5 for.NET Framework 4不支持枚举。