Delete table from EF CodeFirst migration

c# ef-code-first ef-migrations entity-framework sql-server

Question

In EF Code first, I want to drop one column from one table & then delete another table.

After removing one column from class file, automatically one migration file generated.

But how to delete table.

what command need to fire? Do I need to delete complete class file & also remove following line from Context file?

 public DbSet<TableClassName> TableClassNameSet { get; set; }

I use, Add Migration 'TableClassName' command.

So what is best way to remove table?

1
6
8/14/2016 5:46:00 AM

Popular Answer

If you just made the changes in the last migration, you can rollback that migration. Otherwise, just adjust your models and the changes will be picked up in the next migration. To remove a table, simply remove the corresponding DbSet<MyClass> and any references to that class in other parts of your model and EF will add a DropTable to the migration automatically. If you are no longer using the class for non-Entity Framework purposes you can delete it.

5
5/23/2017 12:08:09 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow