Entity Framework Feature Suggestions

Support for Enums

I would really like support for enums in the model. This should of course be available in the designer as well.

1,862 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Mike FlaskoMike Flasko shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →
    completed  ·  Diego VegaDiego Vega responded  · 

    Support for mapping integer columns to enum types will be enabled by the update of the EF core libraries included in .NET 4.5.

    However, in this release we won’t be addressing some of the other ideas mentioned in the comments, such as type conversions in property mapping and design-time support for reverse engineering lookup tables into enum types. Since we are closing this item now, we encourage you to add/vote for those suggestions in separate items.

    23 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • BrianBrian commented  ·   ·  Flag as inappropriate

        We found a simple solution to this. For us we have reference data such as payment types, note types, .... We want to have an enumerated value for each. So in the database, we have an EnumKey column that is a string containing the enumerated value. Then on the entity that corresponds to the table we have a property of the Enumerated Type. And in the implementation of the property, we use the Enum.Parse() method to convert the string to the Enumerated value. Works great and you can use in in linq queries, and in business logic.

      • abatishchevabatishchev commented  ·   ·  Flag as inappropriate

        Felipe Fujiy Pessoto, if you don't need a table for enum, how are you going to store/configure a relation, e.g. order -> order_type?

      • Bruce LeggettBruce Leggett commented  ·   ·  Flag as inappropriate

        Manually updating Enums is worthless! Enums should be GENERATED from look up tables and vice-versa back to the database, even if the Enum tables have to follow a specific schema (i.e. Id, Name, DisplayName columns); however, it would be best if the developer can choose which columns to use for when generating the Enum names, values, and type.

      • David NelsonDavid Nelson commented  ·   ·  Flag as inappropriate

        Even more than just enum support, I would like to see a table mapped as an enum (or even a complex type with properties), where all of the values are determined at design time, and EF does NOT join to the table at runtime, because it knows that the values are static.

      • David NelsonDavid Nelson commented  ·   ·  Flag as inappropriate

        It is embarrassing that EF is supposed to be THE data access technology from Microsoft and it still doesn't have the most basic support for enums that every single other ORM has.

      • Sean TerrySean Terry commented  ·   ·  Flag as inappropriate

        I must admit that with EF being the official way forward, I'm more than a little annoyed that I still can't do with EF what I was doing with Linq to SQL three years ago.

        Code only was the most important one for me, which 4.1 has brought about. Next up is enumeration support.

      • SławekSławek commented  ·   ·  Flag as inappropriate

        It will be great if I could map enum to different values in database for different tables

      • SergeSerge commented  ·   ·  Flag as inappropriate

        I would prefer a general value converter. Comparable to the value converters in WPF. This possibility could also Enums are handled.

      • Moby DiskMoby Disk commented  ·   ·  Flag as inappropriate

        I would like this too - it doesn't have to be a grandiose solution that creates a table mapping the enum IDs to strings or anything. It just needs to do enough to cast the enum to an int and vice-versa. The rest would be icing on the cake,

      • shimmyshimmy commented  ·   ·  Flag as inappropriate

        I want to! Also support for types that have a constructor implementing a certain interface (or in VB that implements widening/narrowing conversion) that can convert and convert back from source type.

      • Daniel F.Daniel F. commented  ·   ·  Flag as inappropriate

        would be great to have ability to map table as an enum ie. I have table OrderStatus with fixed values/rows (New, InProgess, Completed etc.); I'd like to work with enum OrderStatus witn enum members populated from OrderStatus table;

      • j2jensenj2jensen commented  ·   ·  Flag as inappropriate

        I was surprised to find that I couldn't even use a static enum in a selector:
        var dtos = entities.Select(e => new MyDto{Title = e.Title, Type = MyEnum.A});

        It seems like this much at least should be extremely easy to support, right?

      • Jon MillerJon Miller commented  ·   ·  Flag as inappropriate

        I too would like to see support for this and was actually surprised that it isn't already supported in EF 4. What's in EF 4 is really nice, but, it's still missing a lot of basic features that have been in NHibernate for years, such as support for enums.

      ← Previous 1

      Feedback and Knowledge Base