MVC scaffolding does not support Entity Framework 6 or later

前端 未结 4 1381
南笙
南笙 2020-12-29 22:44

Just upgraded to Entity Framework 6 to take a look. I\'m using MVC4.

But i recieve this message when trying to make a controller from a model and context.

相关标签:
4条回答
  • 2020-12-29 22:55

    After a bit more digging

    ASP.NET MVC 4 scaffolding does not support Entity Framework 6 or higher. Support of scaffolding of Entity Framework 6 is targeted for the next release of ASP.NET MVC.

    So looks like ill wait until MVC 5 is properly released

    0 讨论(0)
  • 2020-12-29 22:57

    Workaround which worked for me to scaffold controllers and views for MVC 4 and EF 6:

    1. Use an EXISTING OR NEW MVC 5 Project and copy the Entity Data Model for which you want to create your scaffolding in MVC 4.
    2. Add the Entity Data Model to your MVC 5 DBContext
    3. Create your scaffolded controller and views in the MVC 5 Project which obviously works with EF 6.
    4. Copy the generated views from MVC 5 to your old MVC 4 Project

    This is a solution to generate scaffolding if you do not want to downgrade the EF Version.

    For me this worked out of the box

    0 讨论(0)
  • 2020-12-29 23:01

    ASP.NET MVC 4 scaffolding does not support Entity Framework 6 or later. Support for scaffolding will be included in MVC5. Work around is to use EF5 for scaffolding and then upgrade to EF6.

    http://support.microsoft.com/kb/2816241

    0 讨论(0)
  • 2020-12-29 23:13

    Thought this could use some expanding :) As mentioned above ASP.NET MVC 4 scaffolding does not support EF6 or higher. This means that an older EF, compatible with MVC 4 will have to be installed. To do this:

    1. Open the Package Manager Console:
      • select TOOLS -> Library Package Manager -> Package Manager Console
    2. In the Package Manager Console, uninstall the current EF package by executing the following command:

      UnInstall-Package EntityFramework -Version <version number>

      *Where <version number> is the version number of the EF currently installed.
      *NOTE: to find out what EF version is installed, run the following command in the Package Manager Console:

      Get-Package EntityFramework

    3. To avoid potential metadata problems the providers entry in the Web.config file will need to be removed:

      • Open the Web.config file in the project directory.
      • Delete the following lines:

        <providers> <provider invariantName=System.Data.SqlClient type=System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer /> </providers>

    4. Now, in the Package Manager Console Execute the following command to install Entity Framework 5.0.0:

      Install-Package EntityFramework -Version 5.0.0

    0 讨论(0)
提交回复
热议问题