Add Controller in MVC4 not working

Solution 1:

I tried Fontanka16 solution, but it did not work, it turned out that my DbContext class was missing its default constructor defining the target CE database.

These are my steps summary:

  • Installed the Nuget package EntityFramework.SqlServerCompact.
  • Added the default constructor to my DbContext class.

    public class SchoolContext : DbContext { public SchoolContext() : base("School") { } ... }

  • My connection string is:

    <add name="SchoolContext" connectionString="Data Source=|DataDirectory|School.sdf" providerName="System.Data.SqlServerCe.4.0" />
    

Then it worked.

Solution 2:

I changed the name of my connection string back to DefaultConnection and then it worked, I tried at first to add the default constructor but received some warning about not having the correct assemblies references to.

Solution 3:

I'm new to using EF and MVC, but what I've found is that if you do not define the data connection (comment it out) or rename it in web.config, Visual Studio will allow you to add the controller. If no connection is defined then EF will automatically use SQLExpress. After the controller has been added you can add your connection string back to web.config and the program will function as expected.

//this solution is an excerpt from http://forums.asp.net/t/1838396.aspx/1?Error+while+adding+controller+class+Unable+to+retrieve+metadata+for+MvcMovie+Models+Movie+