我最初在聚合中使用 Enum,这恰好对我来说工作正常,但现在当我将属性更改为 List 时,我发现值没有保存或检索到数据库中,我认为 CodeFirst 会为列表创建一个单独的表并将行映射到那里,但事实并非如此,既不存储也不检索值。
聚合:
public class Trainee: Entity
{
public int TraineeId { get; set; }
public string Name { get; set; }
public int Age { get; set;}
public virtual List<CoursesTypes> CoursesOpted { get; set; }
}
枚举:
public enum CoursesTypes
{
PHP,
Networking,
}
最佳答案
据我了解,当枚举是对象的标准属性时,它们将存储为整数。但是我不确定当您将枚举集合用作属性时会发生什么;感觉这不可能。
此链接应该为您提供有关 Entity Framework 中枚举支持的更多信息 (http://www.itorian.com/2012/09/enum-support-code-first-in-entity.html)。
顺便说一句,如果您首先使用 DbSet 和代码,则不需要从 Entity 派生,我建议使用
public virtual ICollection<CourseTypes> CourseOpted {get; set;}
用于您的收藏属性的签名。
关于c# - List<Enum> in Aggregates Entity Framework Code First,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18074737/