I am writing some UnitTests with NUnit and Entity Framework. How to delete the whole localdb database from Entity Framework level?
Note: I don't want to clear the tables' data. I want to delete the whole database.
Also I am able to create a localdb file in my application working directory provided the database had not been created:
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "");
var testDbFileName = String.Format(@"UnitTestDB.mdf");
var testDbFileNameWithPath = path + @"\" + testDbFileName;
var connectionString =
String.Format(
@"Data Source=(localdb)\V11.0;Initial Catalog={0};Integrated Security=True;AttachDBFilename={1};MultipleActiveResultSets=True",
"UnitTestDB", testDbFileNameWithPath);
//Here would be the code passing connection string to DbContext and so on..
Deleting only the file "UnitTestDB.mdf" is not enough. There is still a reference to the db in SQL Management Studio