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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:23:53+00:00 2026-06-04T08:23:53+00:00

Whenever I navigate to a particular page and then leave it some tables are

  • 0

Whenever I navigate to a particular page and then leave it some tables are deleted. The only thing that differs between this page and the rest is that this page uses a different DbContext. The tables deleted are also part of a different DbContext which is not used on the page visited. This has really got me, any suggestions?

The controller that crashes the page is.

public class GenerationController : Controller
{
    private GenerationDbContext GenerationDb = new GenerationDbContext();
    private string generatedDir = "~/App_Data/Generated";

    //
    // GET: /Generation/

    public ViewResult Index()
    {
        var viewModel = new GenerationIndexViewModel
        {
            Generations = GenerationDb.Generations
                .OrderByDescending(g => g.GeneratedOn)
                .ToList()
        };

        return View(viewModel);
    }

    protected override void Dispose(bool disposing)
    {
        GenerationDb.Dispose();
        base.Dispose(disposing);
    }
}

UPDATE: I just realized I have another page that accesses both DbContexts. For some reason, I can navigate to this page and then leave without deleting tables. It is just this one page that deletes all the tables for the other context.

UPDATE: When I change the Index action to.

public ActionResult Index()
{
    return Content("Hello.");
}

I can navigate between the page and all the other pages fine. No errors about tables being deleted. Ergo, I’m positive it has to do something with the model or database context. Which are so.

public class Generation
{
    public int Id { get; set; }

    [Required]
    public DateTime GeneratedOn { get; set; }

    [Required, StringLength(4000)]
    public string Name { get; set; }
}

public class GenerationDbContext : DbContext
{
    public DbSet<Generation> Generations { get; set; }
}

UPDATE: Using the Database Explorer provided with VWD, there is the Generations table when I navigate to the page. And when I navigate to another page that use a different database context, the Generations table is still the only table. Argh!

  • 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-04T08:23:54+00:00Added an answer on June 4, 2026 at 8:23 am

    Sounds like you have Code First; the first time each dbcontext runs, it checks the database it is configured to connect to. If the schema is not what it expects to find, it flattens the database and recreates tables based on the model classes used by that context.

    There are numerous paths to solve this. The easiest are to combine your contexts, or direct each one to its own separate database.

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

Sidebar

Related Questions

I have a website that I get the below error on whenever I navigate
In facebook, whenever you navigate to a different URL (in some situations), the URL
I am trying to load a page using vbscript. Then i enter some dummy
Whenever I seem to navigate from one Page to another in my Metro app,
I'd like to fire some code whenever a page is shown in the browser:
Whenever I try installing anything using gem, I get this error - murtaza@murtaza-dev:~$ sudo
Whenever I close XCode, the User Info entries that I set for attributes in
Whenever the activity that initiates the scan happens, the android application force closes. It
Ok, so I've got some legacy code from another company that I have to
I have a Visual Studio 2010 project with a Master Page that works fine.

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.