I am trying to create a simple EF code first sample using SQL server compact edition 4.0.
Technologies used include: Visual Studio 2012 Ultimate.
So i created a simple poco class:
namespace MvcApplication2.Models
{
public class Customer
{
public int CustomerId { get; set; }
public string CustomerName { get; set; }
}
}
And a simple context class:
namespace MvcApplication2.Models
{
public class CustomerEntity : DbContext
{
public DbSet<Customer> Customers { get; set; }
}
}
Then I tried to create a controller class with the template: MVC Controller with read/write actions and views using entity framework.
- Model class -> Customer
- Data context class -> CustomerEntity
I got the following error:
Unable to retreive metadata for … Using the same dbcompiledmodel to
create contexts against different types of database servers is not
supported. …
I should say this exact same code worked without problem using LocalDB.
The only difference that I thought was needed, was the addition of the following to the web.config file.
<add name="CustomerEntity"
connectionString="Data Source=|DataDirectory|CustomerEntity.sdf"
providerName="System.Data.SqlServerCe.4.0" />
Am I missing something else?
I know I can’t be the only one having this problem.
Your problem in dublicate DB in EF cache and DB in your App_Data. The easiest way to resolve this problem is to comment your default constructor CustomerEntity, to create controller from template and then uncomment it.