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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:20:52+00:00 2026-06-17T14:20:52+00:00

Currently I am building a web application with MVC 4 and Entity Framework code

  • 0

Currently I am building a web application with MVC 4 and Entity Framework code first scenario.

In the main structure of my application, I have a Dbcontext(BlogDB) to manage some Blog classes. It works fine as it created all the tables I need in the database. Then I created a Area to host an online store. My idea is to create a separated DbContext class(OnlineStoreDB) to handle the classes used for Online Store only.

My problem is once the OnlineStoreDB is fired, entity framework not only created tables for OnlineStore BUT ALSO removed old tables.

My questions are:

  1. If you know a way to keep the old tables?
  2. How exactly to manage the multi EF context classes in one application?

Code:

public class BlogDB : DbContext
{
    public BlogDB ()
        : base("DBConnection")
    {
        Database.SetInitializer(new BlogInitializer());
    }

    public DbSet<Blog> Blogs { get; set; }
    public DbSet<Author> Authors { get; set; }
    public DbSet<Comment> Comments { get; set; }
}

public class OnlineStoreDB : DbContext
{
    public OnlineStoreDB() :
        base("DbConnection")
    {
        Database.SetInitializer(new OnlineStoreInitializer());
    }

    public DbSet<Order> Orders { get; set; }
    public DbSet<Product> Products { get; set; }
    public DbSet<User> Users { 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-06-17T14:20:54+00:00Added an answer on June 17, 2026 at 2:20 pm

    Xavier, welcome to code-first!

    Yes, code-first was a brilliant approach that promised soooo much. But now you’ve hit the catch. There’s no clever mind at Microsoft (or outside as far as I know) who has come up with a smooth way to alter tables intelligently without endangering the data and possibly schema.

    2 Years ago, the implementation strategy was to drop and re-build the DB. That was just intolerable as many of us didn’t have SU access and were stopped in our tracks.

    For all the advantages I found from code first, I prefer DB first. While data can’t be preserved easily, annotations can through buddy classes.

    Microsoft has come up with some clever Migration Strategies. I strongly suggest you read both articles. Code Project 2nd:

    1) http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-code-based-migrations-walkthrough.aspx

    2) http://www.codeproject.com/Articles/504720/EntityplusFrameworkplusCodeplusFirstplusMigrations

    whether you decide to continue with Code-First, they should be enlightening. I sound like a critic but I’m torn between advantages of one and stability of the other.

    Finally, I don’t think you should preserve 2 dbcontexts. Your POCOs should be consolidated under 1 context.

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

Sidebar

Related Questions

I'm currently building a web application (utilizing Zend Framework) and have gotten some of
I am currently building a very small/simple web application in ASP.NET MVC with ADO.NET
I'm currently building a web application using Zend framework 1.11.11 and Doctrine 2.2. I
I'm building an application which (currently) consists of one web application (ASP.NET MVC) and
I currently building web management system using mvc3 In my application i have system
Greetings all: I currently am building a web application, and have been debating whether
I'm currently building a SmartGWT-based web application (using the Portlet Layout). So I have
I'm building a MVC web application (using the Spring MVC framework), and I'm a
I am building a web application that is currently PHP with MySQL. There is
I'm currently building a Jython web app but am concerned about Jython application performance.

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.