How to exclude one table from automatic code first migrations in Entity Framework?

I am using the Entity Framework in Code First mode with automatic migrations enabled. Now I have one entity whose table should not be managed (carried) by EF. Is there a way to turn off automatic migration for one specific object (i.e.Tables)?

+3
source share
3 answers

You can use another DbContextto access the table in question. Migrations are associated with one DbContext(see. Is it possible to have automatic migrations for one DbContext, and not for another in the same project? ).

+1
source

[NotMapped] /.

0

My TEMP is for Dev environments only. I have a separate script that starts the migration, and running the program does not check them. Therefore, in an unexpected case, I was able to call Ignore<ContactView>()and perform migrations using this line. When it was completed, I deleted this line!

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        // comment out this code after migrations are done
        modelBuilder.Ignore<ContactView>();
    }
0
source

All Articles