I\'m using VS 2010 Premium. I have a MVC4 project using SqlCe 4.0 with a entity framework model.
Model is:
public class ProjectBuild
{
p
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:
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.
If you're using VS 2012, you will need to also tell EF to use SQL Compact instead of localDb.
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlServerCe.4.0" />
</parameters>
</defaultConnectionFactory>
An easier way is to install the EF SQL Compact Nuget package.
For more details, check out this blog entry.
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+
I was having this problem when adding a API 2.0 / MVC5 controller with Entity Framework 6 and an MySQL database.
[DbConfigurationType(typeof(MySqlEFConfiguration))]
Comment this class attribute out. Build project. Then adding a controller works for me on MySql.
Uncomment after controller is added and continue as normal.
Ok, this is my evil solution to the problem. I finally made it work. Win8 VS2012 EF5 MVC4
It's a chronological problem not a bug. Source : from Vô Thường's comm http://www.itorian.com/2012/10/unable-to-retrieve-metadata-for.html