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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:30:31+00:00 2026-05-28T07:30:31+00:00

I have an MVC3 project I created using the Code First paradigm and it

  • 0

I have an MVC3 project I created using the Code First paradigm and it works. I created a model inheriting from DBContext, and I can write to the table and all that. I need to add new table and change my model and I using DropCreateDatabaseIfModelChanges<T> But, I lose all my data, due to EF4 will drop end create new DB.

public class MyDbInitializer : DropCreateDatabaseIfModelChanges< MyDb >

Can I use different interface like UpdateDatabaseIfModelChanges<T> if any exist?

My model looks like this:

[Table("Person")]

public class Person
{
    public int ID { get; set; }
    public string name { get; set; }
    public string country { get; set; }
    public string gender { get; set; }
}

public class MyDb: DbContext
{
    public DbSet<Person> People { get; set; }
}

Then I call:

Database.SetInitializer(new MyDbInitializer ());


public class MyDbInitializer : DropCreateDatabaseIfModelChanges< MyDb >

    {
        protected override void Seed(MyDb context)

And this I want to create:

[Table("Person")]

public class Person
{
    public int ID { get; set; }
    public string name { get; set; }
    public string country { get; set; }
    public string gender { get; set; }
}
[Table("NewTable")]

public class NewTable
{
    public int ID { get; set; }
    public string name { get; set; }
    public string position { get; set; }
    public string description { get; set; }
}


public class MyDb: DbContext
{
    public DbSet<Person> People { get; set; }
    public DbSet< NewTable > NewTable { get; set; }

}
  • 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-28T07:30:32+00:00Added an answer on May 28, 2026 at 7:30 am

    Check Code first migrations and EF 4.3 beta where database upgrade is supported with MigrateDatabaseToLatestVersion initializer. No RTM version support this yet.

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

Sidebar

Related Questions

I have developed a project using MVC3 and Code first Entity Framework 4.0 as
I have created a project in MVC 3 using code first and nugget ,
I have created a MVC 3 WCF Rest project using the tutorial described here
I have an ASP.NET MVC 3 project that I just created using the project
First some context: I have an MVC3 .net project which, for the sake of
I have installed MVC3 RTM and when using VS2010 to create a blank project
I am working on a mvc3.0 app using EF code first and mvc scaffolding.
I have created a Helper method in MVC3 Razor project as(Helpers.cshtml) @helper Link(string fileName,
As I have been following a MusicStore tutorial, new MVC3 project created a following
I have created an application installer for my MVC3 project and have followed 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.