title: C# EF Code first - create database and add data
body: <p>I want to create database and add some data. I added EF and I want to use code first. I have these classes:</p>
  
  <pre><code>public class Question
  {
      public bool Sort { get; set; }
      public int QuestionID { get; set; }
      public int Level { get; set; }
      public string Description { get; set; }
      public string Answer1 { get; set; }
      public string Answer2 { get; set; }
      public string Answer3 { get; set; }
      public string Answer4 { get; set; }
      public string RightAnswer { get; set; }
      public bool Show { get; set; }
  }
  
  public class QuestionDb : DbContext
  {
      public DbSet&lt;Question&gt; Questions { get; set; }
  }
  </code></pre>
  
  <p>This is my connection string:</p>
  
  <pre><code>&lt;add name="ConvertCSVtoSQL.QuestionDb" connectionString="Data Source=|DataDirectory|ConvertCSVtoSQL.QuestionDb.sdf"
        providerName="System.Data.SqlServerCe.4.0" /&gt;
  </code></pre>
  
  <p>Now I am creating database like this:</p>
  
  <pre><code>using (var db = new QuestionDb())
          {
  
              foreach (var question in questions)
              {
                  db.Questions.Add(question);
              }
              db.SaveChanges();
          }
  </code></pre>
  
  <p>It creates database but if I have some data in questions which I want to add I get error: </p>
  
  <blockquote>
    <p>The Entity Framework provider type
    'System.Data.Entity.SqlServerCompact.SqlCeProviderServices,
    EntityFramework.SqlServerCompact, Version=6.0.0.0, Culture=neutral,
    PublicKeyToken=b77a5c561934e089' for the 'System.Data.SqlServerCe.4.0'
    ADO.NET provider could not be loaded. Make sure the provider assembly
    is available to the running application. See
    <a href="http://go.microsoft.com/fwlink/?LinkId=260882" rel="nofollow">http://go.microsoft.com/fwlink/?LinkId=260882</a> for more information.</p>
  </blockquote>
  
  <p>I tried to add some initializers but it didn't help:</p>
  
  <pre><code>Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0",@"C:\Path\To\",@"Data Source=C:\Path\To\DbFile.sdf");
  Database.SetInitializer(new CreateDatabaseIfNotExists&lt;QuestionDb&gt;());
  </code></pre>
  
  <p>So where is problem?</p>