I am using VS 2012 and the model first approach in Entity Framework 6 to generate a database in SQL Server Compact 4.0. I have installed the Entity Framework package from NuGet and have added EntityFramework.SqlServer.Compact
to my references. Once I build my model I try to generate the database with the "Generate database from model..." instruction. I can go through the Generate Database Wizard without any problems.
When I run update-database
in the Package Manger Console I get
No migrations configuration type was found in the assembly
Fixing this error I used Enable-Migrations
which gave me a new error
Creating a DbModelBuilder or writing the EDMX from a DbContext created using Database First or Model First is not supported. EDMX can only be obtained from a Code First DbContext created without using an existing DbCompiledModel.
The connection string that was generated is below
<connectionStrings>
<add name="Model1Container"
connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlServerCe.4.0;provider connection string="data source=C:\Users\RSargent\Desktop\CompactDatabase\MyDatabase1.sdf""
providerName="System.Data.EntityClient" />
</connectionStrings>
I have tried using |DataDirectory|
for the connection string path but this doesn't work for me as all I get is a few errors:
Missing required whitespace
<connectionStrings>
<add name="Model1Container"
connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlServerCe.4.0;provider connection string="Data Source=|DataDirectory|\MyDatabase1.sdf""
providerName="System.Data.EntityClient"/>
</connectionStrings>
From the research I have done usually the connection string is the problem in these situations. Am I setting up the connection string correctly? Or does anyone know of another reason why I can't auto-generate a database?