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

  • Home
  • SEARCH
  • 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 4085918
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:39:05+00:00 2026-05-20T18:39:05+00:00

The latest EF Code First NuGet package comes with a custom implementation of IDatabaseInitializer

  • 0

The latest EF Code First NuGet package comes with a custom implementation of IDatabaseInitializer called DontDropDbJustCreateTablesIfModelChanged. As the name implies, when a model change is detected, it will not drop and recreate the whole database, just drop and recreate the tables.

Say I have this model class:

public class User
{
    public string Username { get; set; }

    // This property is new; the model has changed!
    public string OpenID { get; set; }
}

How would one go about implementing an IDatabaseInitializer that doesn’t drop any tables either. In this case, it would just add an OpenID column to the User table?

  • 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-20T18:39:06+00:00Added an answer on May 20, 2026 at 6:39 pm

    I think it is a matter of SQL. So for SQL Server you can write something like:

    public class MyInitializer : IDatabaseInitializer<MyContext>
    {
        public void InitializeDatabase(MyContext context)
        {
            context.Database.SqlCommand(
                @"
                IF NOT EXISTS (SELECT 1 FROM sys.columns AS col
                               INNER JOIN sys.tables AS tab ON tab.object_Id = col.object_Id
                               WHERE tab.Name = 'User' AND col.Name = 'OpenId')
                BEGIN
                    ALTER TABLE dbo.User ADD OpenId INT; 
                END");
        }
    }
    

    But in the same way you can execute such script without adding it to your application which I think is much better approach.

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

Sidebar

Related Questions

I thought I'd experiment a bit with Scott Guthrie's latest post on code-first dev
The following code will not run correctly in IE7 with the latest service packs
When working with my .Net 2.0 code base ReSharper continually recommends applying the latest
I'm using svn for the first time, to maintain a custom version of Wordpress.
The following code works, but I want the groups to show their latest query
In the latest version of WordPress, it gives you the opportunity to view a
After upgrading to the latest version of TortoiseSVN (1.5.2.13595), it's context menu is no
What the latest figures are on people viewing their emails in text only mode
Just installed the latest SDK for iPhone 2.1. When I go to File ->
Does the latest version of the enterprise library ( http://msdn.microsoft.com/en-us/library/cc512464.aspx ) come with the

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.