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 6937585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:22:58+00:00 2026-05-27T12:22:58+00:00

Using Entity Framework Migrations (Beta1), using Update-Database command is all good during development. But

  • 0

Using Entity Framework Migrations (Beta1), using Update-Database command is all good during development.

But when the application is running on some customer’s server somewhere, I really want my application to automatically update it’s database schema to the latest version when it’s started.

Is this possible? Documentation is scarce.

  • 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-27T12:22:59+00:00Added an answer on May 27, 2026 at 12:22 pm

    They aren’t providing a way to do this until RTM, at which point they have promised a command line app and a msdeploy provider.
    Source: http://blogs.msdn.com/b/adonet/archive/2011/11/29/code-first-migrations-beta-1-released.aspx

    Of course not being satisfied with that, the powershell command is stored in the packages directory and is plain text, it appears to just load up an assembly called EntityFramework.Migrations.Commands stored in the same directory.

    Tracing through that assembly I came up with the following

    public class MyContext : DbContext
    {
      static MyContext()
      {
        DbMigrationsConfiguration configuration = new DbMigrationsConfiguration() {
          MigrationsAssembly = typeof(MyContext).Assembly,
          ContextType = typeof(MyContext),
          AutomaticMigrationsEnabled = true,                
        };
    
        DbMigrator dbMigrator = new DbMigrator(configuration);          
        dbMigrator.Update(null);            
      }
    }
    

    UPDATE: after a bit of experimentation I figured out a few more things

    • Performing an update in the static constructor for your context is bad as it breaks the powershell commands, much better off adding the code to application startup another way (Global.asax, WebActivator or Main method)
    • The above code only works when using AutomaticMigrations, you need to set the MigrationsNamespace for it to pickup on manually created migrations
    • The configuration class I was creating should already exist in your project (added when you install the migration nuget package), so just instantiate that instead.

    Which means the code is simplified to

    DbMigrator dbMigrator = new DbMigrator(new NAMESPACE.TO.MIGRATIONS.Configuration());
    dbMigrator.Update(null);        
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently using Entity Framework and am running into this issue: The relationship between
I am using Entity Framework 4 in a desktop application with SQL Compact. I
I have an ASP.NET Dynamic Data application (using Entity Framework) in which I have
I'm using Entity Framework (1st time) on a SQL 2005 database for a data
Using Entity Framework 4 with stored procedures and SQL Server 2008 SP1... When running
I'm using entity framework to connect the database. I've a table(Let's call it File)
I am using Entity Framework in an application i am working on, however when
I am using Entity Framework 4.0 in an ASP.NET 4.0 Web Form. All is
I'm using Entity Framework 4 and with a Database First binding, and EF is
I have developed an application using Entity Framework , SQL Server 2000, Visual Studio

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.