Add controller error unable to retrieve metadata

前端 未结 7 2295
小蘑菇
小蘑菇 2020-12-05 05:25

I want to add controller in my MVC 4 application in VS2012 as this image:

\"add

Model:

相关标签:
7条回答
  • 2020-12-05 05:41

    Don't forget to clean and rebuild before you try to scaffold! That was my mistake.

    0 讨论(0)
  • 2020-12-05 05:41

    I had the same issue and below is the change which fixed the issue for me. Had to change localhost to . And Added Initial catalog=Movies.

    Before

    <add name="MovieDBContext" connectionString="Data Source= localhost\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MoviesDB.mdf;Integrated Security=True" providerName="System.Data.SqlClient"/>
    

    After (fix)

    <add name="MovieDBContext" connectionString="Data Source= .\SQLEXPRESS;Initial Catalog=Movies; AttachDbFilename=|DataDirectory|\MoviesDB.mdf;Integrated Security=True" providerName="System.Data.SqlClient"/>
    

    Reference:

    ASP .Net MVC 4, Invalid value for key 'attachdbfilename'

    0 讨论(0)
  • 2020-12-05 05:47

    My post may help in case someone has the same problem.

    I tried experimenting with EF6 and EF5 in the same project, and I noticed that the <entityFramework> tag was messed up, and got the same problem above.

    Here is what I did, and it solved the problem:

    1. I removed the <entityFramework> tag from Web.config
    2. Uninstalled entity framework from my MVC app using nuget
    3. Installed entity framework to my MVC app again

    After removing the <entityFramework> tag and re-installing EF5 it was fixed, and I can scaffold my controllers again.

    0 讨论(0)
  • 2020-12-05 05:48

    In web.config, delete the AttachDBFilename=|DataDirectory|****.mdf line.

    0 讨论(0)
  • 2020-12-05 05:53

    Change providerName="System.Data.SqlServerCe.4.0 to providerName="System.Data.SqlClient to fix this error.

    0 讨论(0)
  • 2020-12-05 06:01

    In Web.config, set second providerName same as first providerName, and after creating controller, undo that!

    from:here

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