ive a similar problem as this guy: Generate SQL CE database from EF Code-First DbContext class
I know that i need to use
Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");
it must be executed on the application start .. (i am MVC newbie) where can i find such an “Application_Start” in MVC?
EDIT:
I solved my problem: this code must be inserted into the global.asax
You actually don’t need to do that at all. Specify the name of your context class in your web.config:
<connectionStrings> <add name="EntityDemoSite.DataAccess.EntityContext" connectionString="Data Source=|DataDirectory|EntityDemoSite.sdf" providerName="System.Data.SqlServerCe.4.0" /> </connectionStrings>If your context class is in the same project (mine is not) just use name=”WhateverYourContextClassIsNamed” instead.
Check out my sample projects here:
http://completedevelopment.blogspot.com/2011/10/codecamp-nyc-entity-framework-mvc-code.html
note in the web.config of the mvc app the connectionstrings section This is where it all happens. Then in my context class in the data access project you’ll note how it tels it to create the database:
public class EntityContext : DbContext { static EntityContext() { //for example to create a db: Database.SetInitializer(new CreateDatabaseIfNotExists()); ... } }