Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7631793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:26:42+00:00 2026-05-31T06:26:42+00:00

Right now, in development I have the following code in the Global.asax.cs file that

  • 0

Right now, in development I have the following code in the Global.asax.cs file that calls the Entity Framework (v4.1) SetInitializer with my SeedSampleData method. This all works perfectly.

However, I would like to store the SetInitializer “strategy” parameter through a web.config setting so that I can create a deployement script that will automatically set it to new System.Data.Entity.CreateDatabaseIfNotExists<EfDbContext>() instead of my seed method during production deployment.

The reason for wanting to move this to the web.config is that when I roll out a new deployment to the production server I want to make sure that I don’t accidentally leave my seed initializer in the code.

protected void Application_Start()
{
  //TODO: Figure out how to move the following lines to web.config and have a deployment script modify it when going to production.

  //This line is for production
  //System.Data.Entity.Database.SetInitializer(new System.Data.Entity.CreateDatabaseIfNotExists<EfDbContext>());

  //This line is for development
  System.Data.Entity.Database.SetInitializer(new Domain.Concrete.SeedSampleData());

  //... Remainder of Application_Start calls here...
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:26:43+00:00Added an answer on May 31, 2026 at 6:26 am

    If you update to EF 4.3 (which is a good idea anyway), then you can use something like this in your web config:

    <configuration>
      <configSections>
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </configSections>
    
      <entityFramework>
        <contexts>
          <context type=" Blogging.BlogContext, MyAssembly">
            <databaseInitializer type="Blogging.MyCustomBlogInitializer, MyAssembly" />
          </context>
        </contexts>
      </entityFramework>
    </configuration>
    

    Rowan wrote about it in detail here: http://blogs.msdn.com/b/adonet/archive/2012/01/12/ef-4-3-configuration-file-settings.aspx

    If you really want to keep using 4.1, then there is an older syntax that you can use instead. I wrote about it here: http://blog.oneunicorn.com/2011/03/31/configuring-database-initializers-in-a-config-file/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now I have an SSIS package that runs every morning and gives me
How do you undo running bundle install --without development Right now, I have gems
What the best books available right now on Mac and iPhone development ? Thanks
I am fairly new to iPhone development. Right now, I am working on an
I'm new to web development. Right now I'm working on a login feature on
Right now, I keep all of my projects on my laptop. I'm thinking that
Right now I have a database (about 2-3 GB) in PostgreSQL, which serves as
I have two development teams, that come from different groups. Group A develops against
Possible Duplicate: Difference between retain and copy? I'm learning iOS development right now and
I use textmate for website development and compass to compile css stylesheets. Right now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.