MVC “Add Controller” is “Unable to Retrieve Metadata…Config System Failed to Initialize”

前端 未结 11 1043
天涯浪人
天涯浪人 2021-01-04 18:31

From scratch, I made a new solution with two projects: one was MVC 3 and the other a supporting EF 4.2 project. The whole thing builds successfully. From the MVC project I

相关标签:
11条回答
  • 2021-01-04 18:37

    I had installed EF 6 which added:

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

    In my config file. I had other scaffolding issues and so decided to fall back to Ef 5. After uninstalling EF 6 and reinstalling EF 5 I deleted the from the config and then I was able to build my new controller. I discovered this by using the

    PM> Update-Database –Verbose
    
    0 讨论(0)
  • 2021-01-04 18:37

    I found thjis helped when I had this problem:

    Uninstalled the pre-release version of EF and installed EF5 Went to Sql Server Object Explorer and deleted the db. Rebuilt the solution used PM> Update-Database -Verbose

    Perhaps the problem was with pre-release EF or just cleansing the palate was all it needed.

    I'm quite new to all of these but this did let me use the Add Controller scaffolding tool with the "MVC controller with read/write actions and reviews, using Entity Framework" template selected.

    0 讨论(0)
  • 2021-01-04 18:38

    Rename the Model class - worked for me

    0 讨论(0)
  • 2021-01-04 18:38

    Are you sure to have a ConnectionString in your Web.Config file before to create a Controller ? Sometimes we create another project which contains the Entity DB Context and we forgot to add this same connectionString in the Web.Config inside the another project.

    <connectionStrings>
        <add name="Monsters2Entities" ...  />
    </connectionStrings>
    
    0 讨论(0)
  • 2021-01-04 18:48

    I managed to solve my problem by changing the edmx's code generation strategy to T4, adding a EF5 Db Context and replacing %edmxInputFile% in both the *.tt and *.Context.tt files.

    0 讨论(0)
  • 2021-01-04 18:51

    I face this issue "Unable to retrieve metadata..." while I was dding a Controller. Solution for this is as follows.

    1. In Connection String change provider to "system.data.sqlclient" 2.or Remove the Connection String from the Web.config and Add controller and after adding controller again add the connection String.

    It seems this is a bug in MVC. I hope with this you can go ahead.

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