Tech Off Thread

10 posts

Is the DbContext class defined and used differently in the version of C# for Visual Studio 2012 than in Visual Studio 2010?

Back to Forum: Tech Off
  • User profile image
    complete

    Is the DbContext class defined and used differently in the version of C# for Visual Studio 2012 than in Visual Studio 2010?

    I am using code written under Visual Studio 2010 as an example for a project I am writing for with Visual Studio 2012. I am having some difficulty using the DBContext class to instantiate a class. The code seems to required using the namespace System.Data.Entity.Infrastructure; and that does not seem to be defined in the newer System.Data.Entity reference.

     

  • User profile image
    complete

    Let's try this again...

    Is the DbContext class defined and used differently in the version of C# for Visual Studio 2012 than in Visual Studio 2010?

    I am using code written under Visual Studio 2010 as an example for a project I am writing for with Visual Studio 2012. I am having some difficulty using the DBContext class to instantiate a class. The code seems to required using the namespace System.Data.Entity.Infrastructure; and that does not seem to be defined in the newer System.Data.Entity reference.

    To show you what I mean in coding terms, this is the line of code that does not compile:

        using System.Data.Entity.Infrastructure;

    This is the code snap shot in the Visual Studio 2012 that does not compile:

    Generic Forum Image

    It seems that "Infrastructure" is a component of "systems.data.entry.dll" that I have set as a reference:

    Generic Forum Image

    But wait, there is more.  The code, as it exists in the visual studio 2012, is copied from code from a project that does, in fact, compile in visual studio 2010.

    Notice, that there is no little red curly line under Infrastructure when I declare that I am using the namespace System.Data.Entity.Infrastructure in Visual Studio 2010:

    Generic Forum Image

     

    The research I have done on this issue has lead to a dead-end.  This seems to be some sort of required add-in according to this web page::

    Generic Forum Image

    You see, the problem seems to be centered around declaring and using the DbContext class.  But when I tried running this program from Microsoft after I downloaded it, it showed me that it was not for Visual Studio 2012.

    Generic Forum Image

     

  • User profile image
    spivonious

    @complete: Do you need to install the latest EF via NuGet?

  • User profile image
    JohnAskew
  • User profile image
    complete

    What exactly is EF?

    What exactly is NuGet?

    Oh, JohnAskew just gave a link.  I will give it a go.

  • User profile image
    complete

    nugget ran and said everything is up-to-date, but I still have this issue.  Please advise.

  • User profile image
    complete

    Generic Forum ImageI think it has something to do with POCO.  Does anyone know about POCO?

     

  • User profile image
    JohnAskew

    @complete: Plain Old CLR Objects. These are .NET classes stripped down to bare bones, without inclusion of the Entity Framework (EF) namespaces and overhead. They are one of a few options for what generated code you desire EF to create as proxies for your database entities (tables).

    http://blogs.msdn.com/b/adonet/archive/2009/05/21/poco-in-the-entity-framework-part-1-the-experience.aspx

    Sacha Barber is a prolific community member:

    http://www.codeproject.com/Articles/316068/Restful-WCF-EF-POCO-UnitOfWork-Respository-MEF-1-o

    Use NuGet to look for Entity Framework templates for POCO proxy generation...

  • User profile image
    complete

    I saw a tutorial on some other web site that offers example code.

    It was incomplete but I used my powers of reasoning to figure out what was to fill into the blanks.  It had a .edmx file which provided a diagram of the database.  Through poking around on what new classes provided a .edmx file, I found a class to use.  The rest was easy, I just right clicked on the diagram of the database and followed the steps.

  • User profile image
    JohnAskew

    @complete: schweeeet.

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.