none
EF 6.0 Enum Supporty for .Net 4.0 RRS feed

  • Question

  • So, from the pre-release Alpha for EF 6.0 it says that there is Enum support for .Net 4.0

    I uninstalled my EF 5, and got the NuGet Pre fro EF 6.0 but I do not see the Enum feature.  Is it hidden somehow?  The typical right click "Convert to Enum or Add Enum Type" is not showing up for me in the Model designer.

    Thanks,

    JAMES

    NOTE: I would just do the .Net 4.5 thing, but we have lots of clients with XP machines and they do not plan to upgrade them all soon


    JPK


    • Edited by James Klett Friday, January 11, 2013 4:22 PM changed NT to XP
    Thursday, January 10, 2013 8:06 PM

Answers

  • Hi James;

    From my understanding is that if you want to use Enum's with the .Net Framework 4.0 you can only achieve this using Entity Framework Code First approach only. Code First is where you design the database using  POCO, Plane Old CLR Objects, classes, this means that you are not using the ORM designer. Basically the reason is that the designer for .Net 4.0 does NOT support Enum's and therefore you must use Code First approach. 

    The designer in .Net Framework 4.5 was updated to support Enum's and therefore in the 4.5 version you can use the designer to implement Enum's.

    Now there is a way too revers engineer an existing database and use Code First so that you can use Enum's. Please watch this short video to see how to do this. It also gives the website where you can download the tool to revers engineer the model.

    Entity Framework Code First to an Existing Database

    Enum Support - Code First

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by James Klett Friday, January 11, 2013 10:11 PM
    Friday, January 11, 2013 8:41 PM

All replies

  • Hi James;

    Please read and watch a short video on Enum Support - EF Designer.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Thursday, January 10, 2013 9:45 PM
  • Yes, I had already watched that video.  This issue as I wrote it is that I do not have those menu options available to me.

    I am VS2012, Windows 8 and .Net 4.0

    The what's new notes for the alpha EF 6.0 says it contains enum support, but I don't see it

    thanks

    JAMES


    JPK

    Friday, January 11, 2013 4:19 PM
  • Hi James;

    The link that I posted stated this.

    Enum support was introduced in Entity Framework 5. To use the new features like enums, spatial data types, and table-valued functions, you must target .NET Framework 4.5. Visual Studio 2012 targets .NET 4.5 by default.

    In your last post you stated this, "I am VS2012, Windows 8 and .Net 4.0", are you targeting the correct .Net version in your project?

    What type of project are you working on?

    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Friday, January 11, 2013 4:46 PM
  • The NuGet package for the Pre - Alpha EF 6.0 Framework states that is includes enum support for .net 4.0

    I thought I mentioned that in my first post, I am talking about the Pre alpha 6.0 release,

    You can read it here

    http://blogs.msdn.com/b/adonet/archive/2012/12/10/ef6-alpha-2-available-on-nuget.aspx

    scroll half way down and see enum support for 4.0

    JAMES


    JPK

    Friday, January 11, 2013 5:43 PM
  •   

    From the second comment at the bottom of the page from that post Pawel Kadluczka of Microsoft states :

    @John Arete. With EF6 and Code First you can use enums on both .NET Framework 4 and .NET Framework 4.5. For ModelFirst and DatabaseFirst flows you use the EF designer. Only the latest version of the EF Designer supports enums. It requires VS2012 and therefore .NET Framework 4.5 and currently works only with EF5. If in your project you target .NET Framework 4 it will automatically use EF4 (meaning v2 schema and therefore no enums) since this is the only RTM version of EF that works on .NET Framework 4. It sounds to me that what you want is to mix EFDesigner from VS2012 with EF6. This is currently not supported. You could probably hack this somehow but what you would get would be cumbersome. Any reason why you don't want to use EF6 and CodeFirst?

    This may be the issue you are having?

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Friday, January 11, 2013 6:17 PM
  • Maybe I am missing something.  I an new to EF, coming from another tool.  I need want enum support.  I cannot do .Net 4.5 as it will not work on many of our client machines which run Windows XP.  Our application therefore targets .Net 4.0 which is what all our client machines have installed.  

    I am developing in VS2012, and yes I have Windows 8 and yes that comes with 4.5, however my project targets 4.0.  So, when I use EF, ZI do not get enum support.  Now, I read that 6.0 will provide enum support for a .net 4.0 target.  So, that is where I am at.  I have a .Net 4.0 target, and I have installed EF 6.  Yet I do not see enum support.  So either it isn't there or just don't understand what they are saying, which is usually the case

    if you know a way I can get what Iam trying to do, let me know

    I should clarify, I already have an existing large db that I used the DVB first wizard to build my model.  I did not do code first

    thanks

    JAMES


    JPK


    • Edited by James Klett Friday, January 11, 2013 7:33 PM
    Friday, January 11, 2013 7:31 PM
  • Hi James;

    From my understanding is that if you want to use Enum's with the .Net Framework 4.0 you can only achieve this using Entity Framework Code First approach only. Code First is where you design the database using  POCO, Plane Old CLR Objects, classes, this means that you are not using the ORM designer. Basically the reason is that the designer for .Net 4.0 does NOT support Enum's and therefore you must use Code First approach. 

    The designer in .Net Framework 4.5 was updated to support Enum's and therefore in the 4.5 version you can use the designer to implement Enum's.

    Now there is a way too revers engineer an existing database and use Code First so that you can use Enum's. Please watch this short video to see how to do this. It also gives the website where you can download the tool to revers engineer the model.

    Entity Framework Code First to an Existing Database

    Enum Support - Code First

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by James Klett Friday, January 11, 2013 10:11 PM
    Friday, January 11, 2013 8:41 PM
  • Haven't gotten to the vids yet, but did want to point out that I did get POCO when I ran the DB first wizard.  All my objects are plain CLR objects with dbContext not Object Context.  Again, I am new to this so I could be missing some key info on that too.

    Thanks

    I will reply after the vids

    JAMES


    JPK

    Friday, January 11, 2013 8:54 PM
  • Ok, watched the vids, and I ran the reverse engineer code first from db tool.  So now I have built my code two different ways, one with the DB first wizard and now with the new Power Tool reverse engineer kit.  Problems abound.  First, I definitely like the code mapping you get from the latter, however, the tool does not generate partial classes, and does not give me a model to visualize with.  Also, the tool does the whole db, not just the tables I wanted so a lot of extra stuff generated. 

    Now in the second video, on Enums, she shows her code and she does not have any mapping files, she just does the enum and the class as straight object code, so it would appear I do not need the power tool generated mapping anyway.  Arggg, confusing, which is it???

    So, what then is the idea the EF team has for this?  How can I get both together?  A visual model and the code files? and partial classes, (strange to me they would not do that out of the box) 

    thanks again


    JPK

    Friday, January 11, 2013 9:40 PM
  • Hi James,

    Hopefully I can clear this up a bit for you. There is currently no designer that works with EF6, it hasn't been released yet. So you are using the designer that was released with EF5 to create a model that will be used by EF6, which is fine, but the designer doesn't know anything about EF6 so it is generating a model that assumes EF5 is being used.

    Because of that it will only provide you the same features you would get in EF5. Once we release the designer for EF6 then you will be able to do what you are trying to. The post from Pawel was about some hacks you could do to get the designer to generate a model that would give you the functionality you're after while you wait for the designer to be released.

    Does that make sense?


    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.

    Friday, January 11, 2013 9:59 PM
    Moderator
  • Ok thanks to both of you, I think the easiest way to make everyone happy would be to make a .net 4.5 that run on XP, then all this whining and frustration about Enums from me and I am guessing one or two other developers would disappear.  Sadly, the backward compatibility days appear to be over.  The other solution for us is to fork our software into two versions and stop enhancing the XP version  and pressure the clients to upgrade. 

    thanks again

    JAMES


    JPK

    Friday, January 11, 2013 10:11 PM