From everything I've read, EntityFramework should be the bees knees, which you can use CodeFirst to create organizations from POCO's. Awesome! I have carried this out, I allow the EntityFramework default behavior do its factor, and today I am tied to my back from the wall.

Everything I've find out about EntityFramework and MVC3 programs, you can easily alter the DBContext connection string inside your web.config also it should auto-sense, cleanse the meta-data it's cached and regenerate, plus call either the default seed or perhaps your custom seed method for your context. I believe otherwise.

I have got a simple db context class:

namespace AwesomeApp.Models
{
    public class MyContext : DbContext
    {
        public DbSet<Sneeze> Sneeze { get; set; }
    }
}

After getting spent a couple of sprints obtaining the model in position, dealing with the controller and sights, I am prepared to migrate to some staging atmosphere using SQLServer Express 2008. And So I requested mr google how to get this done, also it coldly states about this blog publish, you place the bond string using the entity context because the title, anything else should fall under 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, since it's not creating the table(s) within the database these are merely, but still being able to access the default database. This leaves me with 2 problems and i am positive its borne from the lack of knowledge

  1. Where's the default database situated for SQL Server Express (or perhaps is it CE) that Entity Framework calls automatically?
  2. Whenever you update the bond, can there be more interaction needed through the programmer to obtain the accomplished behavior of changing DB's?

Here's a good example i actually do utilizing an SQLite DB to dynamically alter the path... same logic could be taken for just about any SQL. I put this during my application.xaml of my WPF application (so prob place in the application_start)

' Application-level events, such as Startup, Exit, and DispatcherUnhandledException
' can be handled in this file.

Public Sub New()

    'Attempt to load the db file
    Dim dbFile As New IO.FileInfo(AppDomain.CurrentDomain.BaseDirectory & "Files\database.s3db")

    'Loop till we get liteEntities
    For Each item As System.Configuration.ConnectionStringSettings In ConfigurationManager.ConnectionStrings
        If item.Name <> "liteEntities" Then Continue For

        'Allow us to update this ite
        Dim fi = GetType(ConfigurationElement).GetField("_bReadOnly", BindingFlags.Instance Or BindingFlags.NonPublic)
        fi.SetValue(item, False)

        'Update it
        item.ConnectionString = Replace(item.ConnectionString, "C:\db\Files\database.s3db", dbFile.FullName)

    Next


End Sub