You must Sign In to post a response.
  • Category: .NET

    How to Fixed This Context Conversion issue


    I have created student class in MVC then related created StudentContext also
    created successfully. But when I Created Controller I meet this issue any one fixed this issue.

    This is Error

    Microsoft Visual Studio
    Unable to retrieve metadata for 'Code_First_Approach_in_Entity_Framework.Models.Student'.
    Unable to cast object of type 'System.Data.Entity.Core.Objects.ObjectContext' to type 'System.Data.Objects.ObjectContext'.

  • #766502
    Looks like this is a entity framework version issue. Which version of entity framework are you using in your application. I think you need to use entity framework 5 or below versions for the code to work.
    Miss. Jain
    Microsoft Certified Technology Specialist in .Net

  • #766514
    It seems you are using a version of MVC which is targeting an older Entity Framework version.
    Try upgrade MVC or downgrade your Entity Framework.

    VS Tools-->NuGet package manager-->Package manager console
    PM> uninstall-Package EntityFramework -version 6.1.1
    Press Enter
    PM> Install-Package EntityFramework -Version 5.0.0
    Press Enter

  • #766612
    which version of MVC you are using ? I think your current version does not support Scaffolding Wizard
    see below work around
    1.Open an empty MVC Solution
    2.Open your Package manager console
    3.Type this command (Install-Package EntityFramework -Version 5.0.0 )

    Default Framework
    Select an internet application option of the ASP.NET MVC project template on Visual Studio 2012. By default Entity framework 5 came with it so there is no need to run your package manager console again.

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • Sign In to post your comments