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?
I believe the aim is to delete the database itself and recreate it using EF Code First approach. 1.Open your project in Visual Studio using the ".sln" extention. 2.Select Server Explorer ( it is oftentimes on the left) 3.Select SQL Server Object Explorer. 4.The database you want to delete would be listed under any of the localDB.
A new migrations table will now have been created in the CodeFirstFromExistingDB database. Following this, add a new property named Description to the Product class, with a maximum allowed length of 50 characters, as follows: public int? CategoryID { get; set; }
Using EF6 with ASP.Net Core 5 I found these commands handy during first initialization of the database: Remove-Migration -force; Add-Migration InitialMigration; Update-Database; It removes the last migration (should be the only one), creates it again, then refreshes the database.
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.
f 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.
remove your
public DbSet<TableClassName> TableClassNameSet { get; set; }
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.
To drop a table, you can use DropTable("YourTable")
in the Up()
method of your DBMigration
class.
Also take a look at the following link for more examples on how to customize the migration.
https://msdn.microsoft.com/en-au/data/jj591621.aspx#customizing
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With