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
{
public int ProjectBuildID {get;set;}
public string name {get;set;}
}
public class ProjectBuildContext:DbContext
{
public DbSet<ProjectBuild> builds {get;set;}
}
Below is my connection string:
add name="ProjectBuildContext" connectionString="Data Source=|DataDirectory|DB.sdf"
providerName="System.Data.SqlServerCe.4.0"
When I try to create a new controller with the built in scaffolding too I get the following error:
“Unable to retrieve metadata for ProjectBuild”.”Using the same
DbCompiledModel to create contexts against different types of database
servers is not supported. Instead, create a separate DbCompiledModel
for each type of server being used.
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:
Then it worked.