title: Delete localdb in Entity Framework Code First
body: <p>I am writing some UnitTests with NUnit and Entity Framework.
  How to delete the whole localdb database from Entity Framework level?</p>
  
  <p><strong>Note:</strong> I don't want to clear the tables' data. I want to delete the whole database.</p>
  
  <p>Also I am able to create a localdb file in my application working directory provided the database had not been created:</p>
  
  <pre class="lang-cs prettyprint-override"><code>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..
  </code></pre>
  
  <p>Deleting only the file "UnitTestDB.mdf" is not enough. There is still a reference to the db in SQL Management Studio</p>