title: Entity Framework 5 Code-First dropping/recreating database when app is restarted
body: <p>I'm experimenting with the latest EF 5 CF (in VS2010, not VS2012). I'm generally following the MSDN EF 5.0 Quickstart: Creating a Model with Code First...</p>
  
  <p>Rather than using a console app, my DbContext is in a Windows Service, which will eventually expose various data service methods by hosting a WCF Service (the client will be WPF MVVM)</p>
  
  <p>In the OnStart of the Windows Service, I invoke SetInitializer, and then do a simple query to trigger initialization:</p>
  
  <pre><code>// Start the Windows service.
  protected override void OnStart(string[] args)
  {          
     Database.SetInitializer&lt;MediaLibraryContext&gt;(new MediaLibraryContextInitializer());
     using (var context = new MediaLibraryContext())
     {
        var firstMedia = (from m in context.Medias select m).FirstOrDefault();
     }
     ...
  </code></pre>
  
  <p>And EF CF creates the database from the model and seeds it, as expected.</p>
  
  <p><strong>But when I stop/restart the Service, EF appears to delete the database and recreate it</strong> (or perhaps it's just dropping the tables and recreating them?).  All post-initialization changes I've made to the database are gone, and only the "seed" data is present.</p>
  
  <p>I've worked with EF 4.1 and 4.3, but I've never seen this behavior.  Any ideas where to look???</p>
  
  <p>DadCat</p>
  
  <p>EDIT: I found the problem just after posting this... the Quick start code has the database initialization strategy set to  DropCreateDatabaseAlways.</p>
  
  <p>That's what I get for copy/pasting code without carefully looking at it!</p>
  
  <p>DC</p>