title: How data initialization works?
body: <p>I have problem with initializing data into SQL Server Compact <code>.sdf</code> data file in .NET web application.</p>
  
  <p>I have a data initialization class.</p>
  
  <pre><code>namespace R10491.Models
  {
      public class SampleData : DropCreateDatabaseAlways&lt;LibraryEntities&gt;
      {
          protected override void Seed(LibraryEntities context)
          {
              var categories = new List&lt;Category&gt;
              {
                  new Category{Id=1, Name="Sci-fi"}
              };
  
          }
      }
  }
  </code></pre>
  
  <p>(for testing purposes I use <code>DropCreateDatabaseAlways</code> instead of <code>DropCreateDatabaseIfModelChanges</code>)</p>
  
  <p>This initializer class I call in the <code>Global.asax.cs</code> file:</p>
  
  <pre><code>protected void Session_Start()
  {
     System.Data.Entity.Database.SetInitializer(new R10491.Models.SampleData());
  }
  </code></pre>
  
  <p>(again for testing purposes I call it on every session start).</p>
  
  <p>My connection string definition:</p>
  
  <pre><code>  &lt;connectionStrings&gt;
      &lt;add name="LibraryEntities"
       connectionString="Data Source=C:\Users\Administrator\Documents\Visual Studio 2012\Projects\2OBOP3_KU1\R10491\App_Data\R10491_library.sdf;"
       providerName="System.Data.SqlServerCe.4.0"/&gt;
    &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>But the initialization doesn't work - tables defined in <code>SampleData</code> class are not created nor data are initialized.</p>