title: SQLite with Entity Framework 6 "no such table"
body: <p>I'm trying to implement <a href="https://stackoverflow.com/questions/41923115/how-to-search-large-amount-of-data-based-on-tags">this question</a> with <strong>SQLite</strong> and <strong>EntityFramework 6</strong> code first. I can create the database and there is a file (although empty), but when I try to add an entry to the database it says there is no such table. Yet, when I try to create the table manually (<code>db.Database.ExecuteSqlCommand("CREATE TABLE etc.)</code>) it tells me that the table already exists.</p>
  
  <p>I found some questions about this already, but they're all about the path not being absolute, which is simply not the case here.</p>
  
  <h1>Context</h1>
  
  <pre><code>//Context:
  class MediaContext : DbContext
  {
      public DbSet&lt;MediaModel&gt; Media { get; set; }
  
      public MediaContext(string filename): base(new SQLiteConnection() {
          ConnectionString =
              new SQLiteConnectionStringBuilder()
              { DataSource = filename, ForeignKeys = false }
              .ConnectionString
      }, true)
      {
  
      }        
  }
  </code></pre>
  
  <h1>DAL</h1>
  
  <pre><code>//In the DAL:
  public DataAccessLayer(string path)
  {
     _path = Path.GetFullPath(path); //&lt;--The path already comes full in, I'm just paranoid at this point.
     _connectionPath = _path + @"\MyDatabase.sqlite";
  
     using (var db = new MediaContext(_connectionPath))
     {
        db.Database.CreateIfNotExists();
        db.Database.Initialize(false);                
  
         db.SaveChanges();
     }
  
     public void Generate()
     {
         using (var db = new MediaContext(_connectionPath))
         {
            db.Media.Add(new MediaModel("test"));
            db.SaveChanges(); //&lt;--SQLiteException: SQL logic error or missing database: no such table: MediaModels
  
          }
      }
  </code></pre>
  
  <h1>App.Config</h1>
  
  <pre><code>//App.config:
  &lt;configuration&gt;
    &lt;configSections&gt;
      &lt;section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
      &lt;!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --&gt;
    &lt;/configSections&gt;
    &lt;startup&gt;
      &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /&gt;
    &lt;/startup&gt;
    &lt;entityFramework&gt;
      &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"&gt;
        &lt;parameters&gt;
          &lt;parameter value="v13.0" /&gt;
        &lt;/parameters&gt;
      &lt;/defaultConnectionFactory&gt;
      &lt;providers&gt;
        &lt;provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" /&gt;
        &lt;provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /&gt;
      &lt;/providers&gt;
    &lt;/entityFramework&gt;
    &lt;system.data&gt;
      &lt;DbProviderFactories&gt;
        &lt;remove invariant="System.Data.SQLite.EF6" /&gt;
        &lt;add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" /&gt;
        &lt;remove invariant="System.Data.SQLite.EF6" /&gt;
        &lt;add name="SQLite Data Provider" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" /&gt;
      &lt;/DbProviderFactories&gt;
    &lt;/system.data&gt;
  &lt;/configuration&gt;
  </code></pre>