1

I have an MVC website with its own database and everything is working fine. Now I want to access a table of a database from a different MVC site. I added the connection string in the Web.config and named it OldMvcDB. Then I added a class to access this table:

public class OldSiteDB : DbContext
{
    public OldSiteDB() : base("name=OldMvcDB") { }

    public DbSet<OldTable> OldTables { get; set; }
}

When I try to access this table, I get the error: The model backing the 'OldSiteDB' context has changed since the database was created.

This is because the old database has a lot of other tables so the context doesn't match.

How can I access this one table without having to duplicate all the items in my new site?

Garrett Fogerlie
  • 4,450
  • 3
  • 37
  • 56

1 Answers1

1

You should add the following to your class constructor:

Database.SetInitializer<OldSiteDB>(null);

From this SO answer.

Community
  • 1
  • 1
thepirat000
  • 12,362
  • 4
  • 46
  • 72