michael
michael

Reputation: 647

Entity Framework 6 generates tables in database - but I don't want them

I use ASP.NET MVC 5, Entity Framework 6. I use database-first methodology. I created database and then ASP.NET MVC application but Entity Framework adds tables to my database, for example: _Migrationhistory, People (I have my own table Person in database).

This is my context in application:

public class DatabaseContext : DbContext
{
        public DatabaseContext() : base("DatabaseContext") { }

        public DbSet<Person> Persons { get; set; }
}

What is going on?

Upvotes: 0

Views: 107

Answers (1)

Arvin Yorro
Arvin Yorro

Reputation: 12147

EF creates the tables by default, unless you explicitly tell it not to. More about it here.

You can disable the Initializer using the following code:

Database.SetInitializer<DatabaseContext>(null);

Sample usage:

public class DatabaseContext : DbContext
{
    // This static constructor disables the initializer.
    static DatabaseContext()
    {
        Database.SetInitializer<DatabaseContext>(null);
    }

    public DatabaseContext() : base("DatabaseContext") { }

    public DbSet<Person> Persons { get; set; }
}

Upvotes: 3

Related Questions