Entity Framework CTP 5 - Code First Mappings - Can't map properly an enum list

风格不统一 提交于 2019-12-10 20:08:56

问题


I have the following

[DataContractAttribute]
public class Animal
{
    [Key]
    [XmlElement(ElementName = "Id")]
    [DataMember()]
    public Guid Id
    {
        get;
        set;
    }

    [XmlElement(ElementName = "AnimalType")]
    [DataMember()]
    public List<AnimalType> AnimalType
    {
        get;
        set;
    }
 }

And i map it through the code first approach with EF to tables

  modelBuilder.Entity<Animal>().ToTable("Animal");

As you see I have not performed some complex mapping, but the List of AnimalType enumerations did not get mapped automatically to any columns/tables in the DB. Do i need to add some extra code to the model builder to control the mapping of an enumeration list ?


回答1:


As of EF CTP5, enums are not supported yet. The team announced that they are going to fully support enums in their next RTM version which is targeted to be released on the first quarter of 2011.




回答2:


I know for the longest time, enums weren't supported by EF, though I don't know if that is still the case or not.

Either way, I think there is a general problem with having EF handle a list of a type other than another entity. What is the primary key? What is the value? Should it try to store the data in one column or create a separate table and create a foreign key constraint? These are questions that will likely need to be answered before your model can be converted into a database schema.



来源:https://stackoverflow.com/questions/4452201/entity-framework-ctp-5-code-first-mappings-cant-map-properly-an-enum-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!