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?

1

1 Answer 1

1

You should add the following to your class constructor:

Database.SetInitializer<OldSiteDB>(null);

From this SO answer.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.