none
Enumeration in EF4 (beta)

    Question

  • Hello.

    Please answer: support EF4 (beta) mapping for enumeration types?

    Wednesday, May 27, 2009 7:00 AM

Answers

  • We did hear you, and this is definitely something we will do in a future release.  It pains me to say that we were just unable to get enums into this release.  It's small consolation I'm sure, but I'll give you just a tiny bit of background...

    We did quite a bit of design work for enums, and had it on the schedule multiple times.  The problem is a combination of two things:

    1) This "little" feature turns out to be one of those things that touches every single part of the product.  We have multiple separate feature teams which work on the product, and to get this right every one of them have to be involved in a coordinated way (or you can have a smaller number of individuals work on it, but they still have to coordinate with the primary owners of the areas).  We need changes in object services, in the metadata system, in mapping, in query, in update, in sql generation, in the designer, etc. etc.  So the result was that even though it's not a lot of work in anyone place, it adds up to a lot more than it seems on the surface.

    2) We were so focused on the other major features like the core parts of POCO for change tracking, removing metadata/attributes requirements on entities, foreign key support (coming post beta 1), model first, improved sql generation, etc.  That this kept getting pushed or postponed one way or another.

    Again, I know this doesn't help when you are trying to build your app and struggling with the fact that you want to use an enum without having to work around the EF's limitation in this area, but there it is.  When it comes to the painful decisions required to actually ship, this was one we had to make for this release.

    Our plan is to lock down on EF4 as soon as we reasonably can so that we can get some folks started early on a few very important features like this which just didn't make the box for EF4 and be absolutely sure they make the next release.

    - Danny
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Monday, June 01, 2009 5:34 AM
  • No - as far as I know enumeration support is not planned for EF4.
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Wednesday, May 27, 2009 10:35 PM
    Moderator

All replies

  • No - as far as I know enumeration support is not planned for EF4.
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Wednesday, May 27, 2009 10:35 PM
    Moderator
  • May I ask why?

    It seems like totally missing the point if you implement POCO support and not support enum properties.
    EF4 is very impressive so far, it almost gives us in the POCO camp what we need, please don't mess up on the small things.

    If I want to go TDD with POCO classes and create an "Order" class that has a "Status" property which is an enum.
    And then decide to map that to EF4 and finds that EF4 can not handle that, then we _still_ need to resort to NHibernate..

    It's not even a problematc feature to implement, just treat every enum as if it was an integer.
    So when the POCO model is validated, it says OK if it should have an int property but finds an enum property.

    And do the same in the Linq queries, just translate enums to ints.

    (After all, they are compatible at reflection level, you can pass an integer value to a enum property/param/field w/o any extra code at all)

    //Roger
    My Blog: http://www.RogerAlsing.com
    Thursday, May 28, 2009 4:58 AM
  • Hi *,

    and what if your enum in DB is char(1), for example? Then it's not simple int mapping ([1]). You need to tell to the enum what value is what char. It's not hard, i.e. attributes do it well, but creates a couple of small challenges.

    BTW Noam, is there some consideration for future versions?

    [1] And if it will support only int, IMO there will be a lot of complains from others that's incomplete. ;)
    Jiri {x2} Cincura
    Thursday, May 28, 2009 9:26 PM
  • >>and what if your enum in DB is char(1), for example?

    .NET enums can only derive from integer values.
    And from a code first (e.g. DDD with POCO classes) , DB schema is not interesting.
    If you claim to support POCO, then you have to support normal enums, otherwise it's not POCO.
    My Blog: http://www.RogerAlsing.com
    Friday, May 29, 2009 1:38 AM
  • Char(1) as enumeration - is very often variant for legacy systems.

    For example, NHibernate support mapping between enumeratin and char(1) using NHibernate.UserTypes.IUserType, but native variant is mapping enumeratin in DB as int.

    Friday, May 29, 2009 2:22 AM
  • It's very sadly.
    But, thank you for answer.
    Friday, May 29, 2009 2:26 AM
  • So, should we consider this to be the final answer?
    No enumeration support including the very 10-4 RTM?
    Totally agree with Michail Romanov - that doesn't seem very logical together with the great effort to support POCO.

    Best Regards,
    Mikhail Kirillov
    Friday, May 29, 2009 6:57 AM
  • No - as far as I know enumeration support is not planned for EF4.
    This posting is provided "AS IS" with no warranties, and confers no rights.

    This is soooo very bitterly disappointing :-(  Enum support was one of the last remaining features I'd been waiting for in order to switch to the Entity Framework.

    From previous MSFT responses to this, both here in the forums and on Connect, I thought this was one the the primary "we hear ya" features that were definitely going to be addressed.

    See the following thread form over a year and half ago on about this:

    http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/17d2d771-00c0-4579-9120-84aa43cbab57

    Please also vote on the Connect bug for this if you feel it should be addressed:

    https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=365701
    Saturday, May 30, 2009 5:18 PM
  • We did hear you, and this is definitely something we will do in a future release.  It pains me to say that we were just unable to get enums into this release.  It's small consolation I'm sure, but I'll give you just a tiny bit of background...

    We did quite a bit of design work for enums, and had it on the schedule multiple times.  The problem is a combination of two things:

    1) This "little" feature turns out to be one of those things that touches every single part of the product.  We have multiple separate feature teams which work on the product, and to get this right every one of them have to be involved in a coordinated way (or you can have a smaller number of individuals work on it, but they still have to coordinate with the primary owners of the areas).  We need changes in object services, in the metadata system, in mapping, in query, in update, in sql generation, in the designer, etc. etc.  So the result was that even though it's not a lot of work in anyone place, it adds up to a lot more than it seems on the surface.

    2) We were so focused on the other major features like the core parts of POCO for change tracking, removing metadata/attributes requirements on entities, foreign key support (coming post beta 1), model first, improved sql generation, etc.  That this kept getting pushed or postponed one way or another.

    Again, I know this doesn't help when you are trying to build your app and struggling with the fact that you want to use an enum without having to work around the EF's limitation in this area, but there it is.  When it comes to the painful decisions required to actually ship, this was one we had to make for this release.

    Our plan is to lock down on EF4 as soon as we reasonably can so that we can get some folks started early on a few very important features like this which just didn't make the box for EF4 and be absolutely sure they make the next release.

    - Danny
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Monday, June 01, 2009 5:34 AM
  • Hi Danny,

    Thanks for the info on this, it's reassuring to hear enum support is still on the radar for a future release.  I do appreciate that you guys have had a lot of features on your plate for EF4, and from looking at the feature set, admittedly, you're probably right to prioritise them above enum support.

    I know you probably can't comment on future releases, but I hope we won't have too long a wait for the next version of the EF after VS2010 RTMs.  Do you think there's any chance of an out of band release, or possibly another Visual Studio feature bump release, similar to what was done with VS2008/.NET 3.5 SP1?

    -Dan
    Monday, June 01, 2009 10:55 AM
  • Microsoft history (since 1987 in my case) tells us that any new or radically changed Microsoft Technology of any flavor begins to work the way the developer community would like it to work on or after the date when Service Pack 1 for that technology appears.  Unless one of the Microsoft folks wants to (or can) say differently, I don't see why EF4 support of enums in POCO's would vary from the "established historical pattern".  Yes, I wish it were there on day one, but I'm not going to "bet the company" on it until, like fine wine, it has aged and matured to the point of being worthy of being my ORM tool of choice.  Will I work the tutorials and samples in the mean time? Yes.  Bet the company on EF4? No.
    If you think development is tough now, try doing it on punched cards :-)
    Monday, June 01, 2009 2:02 PM
  • Dan,

    It's very unlikely that we will do an out of band release of the core product.  We are looking at some ways to at least do CTPs of features that can layer on top of the core product, and you'll be seeing the first round of that in a web release soon, but something like enums requires changes down in the core of the product and will only be available when we can update the product itself.

    There's no announcement or schedule or any such thing, but it's not hard to figure that there will be a service pack (when has there not been one), and some additional features may appear in that service pack.  That said, we're trying very hard to get the EF team back in sync with the .net framework as a whole so that we can do a full release cycle.  EF4 was really only half a release for us since we shipped the first release of the EF with 3.5 sp1.  It will be very good for the team and the product if we can do a full release for the next round.

    So I guess I'm saying that I hear you telling us that enums are very important, and you'd like them as soon as possible, but at the same time I don't think it's super likely that they will arrive before the next regular release of .net.

    - Danny
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Monday, June 01, 2009 3:53 PM
  • Does EF4 use the new Managed Extensibility Framework (MEF)?  If not, start looking into it in terms of easier/faster-to-market changes to EF4, like enum support for POCO's.  Worst case, we can cobble together our own solution until such time as Microsoft can provide a supported one.  Just food for thought.
    If you think development is tough now, try doing it on punched cards :-)
    Monday, June 01, 2009 3:58 PM
  • No, EF4 does not currently use MEF in the runtime.  There is some use of MEF coming in the designer for extensibility there, but I suspect that the work needed to provide appropriate extensibility to the EF runtime is more about continuing to work on core EF abstractions than the hooks MEF will provide.  That said, we will certainly keep our eyes open for opportunities.
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Monday, June 01, 2009 4:04 PM
  • As others have said as of right now we don't support Enums :(

    However I have just written another tip called Tip 23: How to fake Enums in EF 4 which shows an interesting workaround.

    Hope this helps

    Cheers
    Alex
    Alex James (Microsoft)
    Friday, June 05, 2009 8:18 PM
    Moderator
  • so alex it appears that on your blog posting u mentioned there is a possiblity that enum might make it to the release. Can u let us know if it scheduled or is it pushed to the next version of Ef.

    Thanks
    Zeeshan
    Tuesday, August 11, 2009 4:36 AM
  • Zeeshan,

    It looks highly unlikely that Enums will make it into .NET 4.0

    Alex
    Alex James (Microsoft)
    Tuesday, August 11, 2009 2:07 PM
    Moderator
  • Zeeshan,

    It looks highly unlikely that Enums will make it into .NET 4.0

    Alex
    Alex James (Microsoft)

    How's the schedule looking?  Does it look like there's any spare time left over to address enum support?  I heard the schedule for VS2010 was set back by a couple of months due to teething issues with the new WPF shell, so if there's *any* spare time left at all, enum support is absolutely top of my list.

    Actually, this is such a key scenario, I'd happily take a delay in the entire VS2010 product release just to fit this feature in.
    Tuesday, September 08, 2009 9:41 AM
  • With a product release as large as VS2010 involving many, many teams, one part of the product running late doesn't lead you to allow other teams to slip in more features.  It's just not realistic if you ever want to ship--especially something like enums which touches essentially every part of the EF stack (as I mentioned above).

    It pains me to say it, but enums in the EF just aren't going to be part of .NET 4.0.

    - Danny
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Tuesday, September 08, 2009 2:59 PM
  • It pains me to say it, but enums in the EF just aren't going to be part of .NET 4.0.

    - Danny

    Was just holding onto that tiny glimmer of hope, I knew it was a bit of a long shot :-)

    Still, beta 2 is looking like it's going to be great (other than missing enums :-P).  Will the EF be pretty much feature complete by that point?  Any idea when beta 2 is due btw?
    Wednesday, September 09, 2009 9:02 AM
  • I could answer your last questions, but then I'd have to lock you in a room and not let you tell anyone else or act on the knowledge.  :-)

    Actually I don't have a date for you for beta 2, but it's not a *long* way off.  As far as feature complete goes, there's certainly a push to make beta 2 feature complete across vs and .net.  I wouldn't count on the fact that no other thing will appear in the product after beta 2 (there's always someone trying to squeeze something in), but I wouldn't many additional features if any.

    - Danny
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Wednesday, September 09, 2009 3:35 PM
  • It's been a while since this has been requested - any word on support??
    Entities should not be multiplied beyond necessity
    Saturday, August 14, 2010 5:29 PM
  • Hi,

    I've been playing around with EF4 lately and was wondering how to implement some sort of enum. I ended up with this approach:

     

    • In the db, have a column of type int
    • in your edmx-file, set the getter and setter to private, name it something like db+"the original name" (My column was Type, so i named it dbType
    • Create a partial class and add something like this:
          public enum TypeEnum { Normal = 1, Awesome = 2 }

          public partial class Comment : EntityObject
          {
              public TypeEnum Type
              {
                  get { return (TypeEnum)this.dbType; }
                  set { this.dbType = (int)value; }
              }
          }
    Thursday, September 16, 2010 8:12 PM
  • Ok I've had it with the lacking enum support so I've added my own :-)

    http://rogeralsing.com/2010/11/10/entity-framework-4-enum-support-in-linq/


    My Blog: http://www.RogerAlsing.com
    Wednesday, November 10, 2010 5:09 PM
  • Wow, Roger, good work.  Been following this thread for awhile. 
    Thanks, Terrence
    Wednesday, November 10, 2010 5:21 PM