Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Most efficient way to delete database data in Entity Framework 4?

For integration testing I need to wipe all data information in a database. I'm using Entity Framework 4 What's the most efficient way? Would be nice if I don't need to specify table or class names every time I add a new class to the model.

Thanks!

like image 965
Rodrigo Juarez Avatar asked May 13 '26 21:05

Rodrigo Juarez


2 Answers

Most efficient way to delete database data is to drop all tables and recreate all tables.

like image 87
Sergey Vedernikov Avatar answered May 19 '26 03:05

Sergey Vedernikov


This may not be the fastest, but it is the simplest. It even clears your connection pool:

using (var context = new DataContext())
{
    context.Database.Delete();
}
like image 27
Frank Schwieterman Avatar answered May 19 '26 03:05

Frank Schwieterman