From everything I have read, EntityFramework is supposed to be the bees knees, that You can use CodeFirst to generate entities from POCO’s. Awesome! I’ve done this, I let the EntityFramework default behavior do its thing, and now I’m stuck with my back against the wall.
Everything I have read about EntityFramework and MVC3 applications, you can just change the DBContext connection string in your web.config and it should auto-sense, cleanse the meta-data it has cached and regenerate, plus call either the default seed or your custom seed method for that context. I beg to differ.
I’ve got a very simple db context class:
namespace AwesomeApp.Models
{
public class MyContext : DbContext
{
public DbSet<Sneeze> Sneeze { get; set; }
}
}
After having spent a few sprints getting the model in place, working with the controller and views, I’m ready to migrate to a staging environment using SQLServer Express 2008. SO I asked mr google how to do this, and it blatantly states on this blog post, you set the connection string with the entity context as the name, everything else should fall into place.
<connectionStrings>
<add name="MyContext"
connectionString="Server=server;Database=awesome_sauce;User ID=noob;Password=noob;Trusted_Connection=False;"
providerName="System.Data.SqlClient"/>
I call shenanigans, as its not creating the table(s) in the database i have listed, and still accessing the default database. This leaves me with 2 problems and i’m positive its borne from my ignorance
- Where is the default database located for SQL Server Express (or is it CE) that Entity Framework calls by default?
- When you update the connection, is there more interaction required by the programmer to get the achieved behavior of swapping DB’s?
Here is an example i do using an SQLite DB to dynamically change the path… same logic can be taken for any SQL. I put this in my application.xaml of my WPF app (so prob put in your application_start)