I'm trying to deploy my first alpha version of the system online for any couple of individuals to begin using. On development I make heavy utilisation of the DropCreateDatabaseOnModelChange<TContext> (I do not get it before me right now and so i can't verify the precise title) to re-initialize my dev database each time my model changes. This occurs within the Global.asax.

However, I don't want this to occur on my small hosting company where most people are entering real data. I have to handle all db migrations on the website myself so information is maintained.

I'd considered #ifdef DEBUG tags to avoid the database initializer from being known as, however i can't stand that solution. At this time, I've the debug version used, therefore if they are available across any errors it is simple that i can see and debug them (this is very alpha, so merely a choose couple of artists are using it and know to anticipate errors).

The other options must i prevent Push DB shedding by EF4 code first?

How about inversion of control:

var initializer = container.Resolve<IDatabaseInitializer<Context>>();
Database.SetInitializer(initializer);

According to your IoC configuration you'll either return developement or production initializer. You could have different configuration apply for each build configuration so that you can also provide IoC container set up in a different way.

public class ThrowExceptionInitializer : IDatabaseInitializer<Context>
{
    public InitializeDatabase(Context context)
    {
        // Custom exception
        throw new InvalidVersionException("The new application version is not supported by the database version");
    }
}

As @Johann states, the ConditionalAttribute is most likely the cleanes solution here:

[Conditional("DEBUG")]
private void InitializeDb()
{
    // Initializer code here
    // DropCreateDatabaseOnModelChange<TContext>
}

as well as in Global.asax:

public void Application_Start // or wherever it is you're initializing
{
    // This will only be called if the DEBUG constant is defined
    InitializeDb();
}

You could utilize the Conditional attribute but it's not too not the same as the #ifdef

You could produce a new Configuration (additionally to Debug and Release). You would define a Conditional Compilation Symbol for that new configuration. For instance basically produced a brand new configuration known as LocalDebug (with similar configurations in the default debug) I'd adding LOCALDEBUG towards the Conditional Compilation Symbols. With this particular defined you should use:

#if LOCALDEBUG
  //do database stuff
#endif

You'll be able to still deploy the built-in debug configuration which section won't fire.

If you work with sql express in development and this is not on your production box you are able to filter through the connection.

protected void Application_Start(object sender, EventArgs e)
{
  using (var db = new MyDb())
  {
    if (db.Database.Connection.DataSource.IndexOf("sqlexpress", StringComparison.InvariantCultureIgnoreCase) > -1)
    {
        Database.SetInitializer(new MyDbInitializer());
    }
  }
}