Note that there are some explanatory texts on larger screens.

plurals
  1. POEntity Framework 5 Code-First dropping/recreating database when app is restarted
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload