none
Model First Appraoch - Dealing with Enumurations in ADO.NET EF 5.0 RRS feed

  • Question

  • We have a project where we would like to follow model first approach. We would like to design the Model first in the designer then generate the database. We are planing to use the new enumuration support and have an issue to support the following scenarion.

    We have a "subscription" entity which can more than one category. The possible values of categories are A,B,C,D.

    We have created a entity as Subscription. We have created a enum type as category. How do I specify the one to many scenario? Please advice.

    Saturday, August 18, 2012 12:46 AM

Answers

  • Hi,

    EF cannot currently have a one-to-many relationship with an entity and an enum.

    You could do it via normal entity mapping, so the category is an actual entity. The category entity could just be a stub class containing a key and your enum value though if you like.


    We are seeing a lot of great Entity Framework questions (and answers) from the community on Stack Overflow. As a result, our team is going to spend more time reading and answering questions posted on Stack Overflow. We would encourage you to post questions on Stack Overflow using the entity-framework tag. We will also continue to monitor the Entity Framework forum.

    There is currently a work item on codeplex to support collections of scalar types, which is what multiple enums would be. It is here if you want to vote for it or talk about enums in the description. http://entityframework.codeplex.com/workitem/300

    Monday, August 20, 2012 6:10 PM
    Moderator

All replies

  • Hi Arasheed,

    Welcome to the MSDN forum.

    I am not sure if what you want to know is how to convert a scalar property to enumerations property. If so, after you created Enum types already, you can click a property which you want to set as a Enum type in entity design window. Then set the Type in Properties Explorer as the Enum type you have created.

    If I misunderstood anything, please feel free to let me know.

    Good day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    Monday, August 20, 2012 6:53 AM
  • Hi,

    EF cannot currently have a one-to-many relationship with an entity and an enum.

    You could do it via normal entity mapping, so the category is an actual entity. The category entity could just be a stub class containing a key and your enum value though if you like.


    We are seeing a lot of great Entity Framework questions (and answers) from the community on Stack Overflow. As a result, our team is going to spend more time reading and answering questions posted on Stack Overflow. We would encourage you to post questions on Stack Overflow using the entity-framework tag. We will also continue to monitor the Entity Framework forum.

    There is currently a work item on codeplex to support collections of scalar types, which is what multiple enums would be. It is here if you want to vote for it or talk about enums in the description. http://entityframework.codeplex.com/workitem/300

    Monday, August 20, 2012 6:10 PM
    Moderator
  • Thank you!!
    Saturday, August 25, 2012 4:43 PM