title: How to detach a LocalDB (SQL Server Express) file in code
body: <p>When using LocalDB .mdf files in deployment you will often want to move, delete or backup the database file.
  It is paramount to detach this file first as <a href="https://stackoverflow.com/questions/13275054/ef5-cannot-attach-the-file-0-as-database-1/15832184#comment23237296_15832184">simply deleting it will cause errors because LocalDB still keeps a registration of it</a>. </p>
  
  <p>So how is a LocalDB .mdf file detached in code?</p>