我最初在聚合中使用 Enum ,这对我来说工作得很好,但现在当我将属性更改为 List 时,我发现这些值没有在数据库中保存或检索,我认为 CodeFirst 会创建一个单独的表并映射其中的行,但事实并非如此,值既不被存储也不被检索。
Agg:
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; }
}
Enum:
public enum CoursesTypes
{
PHP,
Networking,
}
据我了解,当枚举是对象的标准属性时,它们会存储为整数。但我不确定当您使用枚举集合作为属性时会发生什么;这感觉不太可能。
此链接应该为您提供有关实体框架中枚举支持的更多信息(http://www.itorian.com/2012/09/enum-support-code-first-in-entity.html http://www.itorian.com/2012/09/enum-support-code-first-in-entity.html).
顺便说一句,如果您首先使用 DbSet 和代码,则不需要从 Entity 派生,我建议使用
public virtual ICollection<CourseTypes> CourseOpted {get; set;}
用于您的收藏属性的签名。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)