To drop all tables in Entity Framework Core, you can use the following code:
main.cs396 chars16 lines
This method uses raw SQL to query for all tables in the database and generates a DROP TABLE
statement for each table. Then it executes the generated SQL using sp_executesql
.
You can call this method passing an instance of your context:
main.cs74 chars5 lines
Note that this is not recommended in production environments, as it will permanently delete all data in the database.
gistlibby LogSnag