title: System.Data.SQLite 1.0.91.0 and EF6.0.2
body: <p>Has anyone gotten the new System.Data.SQLite 1.0.91.0 to work with Entity Framework 6 in Visual Studio 201#? If you have, how did you do it? </p>
  
  <p>Update - 20 Mar 2014: System.Data.SQLite 1.0.92.0 has been released but I had no luck creating an EDMX in VS2013 :( I ended up using using Package Manager (because EF6.#.# is a dependency in the new SQLite NuGet package):</p>
  
  <pre><code>uninstall-package entityframework -force
  </code></pre>
  
  <p>restart VS2013 and put the older EF5 on to get VS2013 to generate an EDMX from an existing database:</p>
  
  <pre><code>install-package entityframework -version 5.0.0
  </code></pre>
  
  <p>Note: This was not a complex, multi-table SQLite relational database test so I am not sure what other problems will arise if I do use anything with more than a couple Navigation (FK) relationships :/</p>
  
  <p>ANSWER for EDMX/Model First: (Update - 2 Mar 2014) I found a work-around but it is not consistent enough and requires too many steps to consider it a valid solution. Basically:</p>
  
  <ul>
  <li><p>you make all the Class(es) file(s), </p></li>
  <li><p>make a connection to an existing SQLite database with tables, </p></li>
  <li><p>modify the web/app.config to as described by mistachkin in the still outstanding SQLite Trouble Ticket (<a href="http://system.data.sqlite.org/index.html/tktview?name=7b8fd3ef77">http://system.data.sqlite.org/index.html/tktview?name=7b8fd3ef77</a>), including faking the cdsl/.ssdl/.msl pieces, and</p></li>
  <li><p>then manually create all the Entity Models in the Designer in an Empty EDMX before rebuilding the project and then...</p></li>
  <li><p>your right click on an Entity and choose 'Update from database'... </p></li>
  </ul>
  
  <p>Sometimes EF/VS2013 will add the .tt/DbContesxt and sometimes they don't. Way too 'hit or miss' :(</p>
  
  <p>ANSWER for "Code First" with and without an existing SQLite database (based on PMCB, Drexter, and Jimi's suggestions). Note however that you cannot generate any EF models or EDMX files [sic - Conceptual Schema Definition Language (.CSDL), Store Schema Definition Language (.SSDL), and Mapping Specification Language (.MSL)] automatically in Visual Studio 2013. I did not try manually creating the EDMX files to see if they would be palatable to EF and even if I did, it seems to me that doing all the manual creation/mapping/changes/XML edits defeats the whole purpose/concept of a entity based framework...</p>
  
  <pre><code>&lt;connectionStrings&gt;
      &lt;add name="DogsContext" connectionString="Data Source=|DataDirectory|\dogs.s3db;" providerName="System.Data.SQLite" /&gt;
  &lt;/connectionStrings&gt;
  &lt;entityFramework&gt;
      &lt;providers&gt;
         &lt;provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" /&gt;
      &lt;/providers&gt;
  &lt;/entityFramework&gt;
  &lt;system.data&gt;
      &lt;DbProviderFactories&gt;
        &lt;remove invariant="System.Data.SQLite" /&gt;
        &lt;add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" /&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, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" /&gt;
      &lt;/DbProviderFactories&gt;
  &lt;/system.data&gt;
  </code></pre>
  
  <p>Here is the test Class (note that I had to change the DogID to Int64 to get it to work with SQLite...):</p>
  
  <pre><code>using System.Data.Entity;
  
  namespace WebApplication1.Models
  {
      public class Dog
      {
          public Dog() { }
  
          public Int64 DogID { get; set; }
          public string DogName { get; set; }
      }
  }
  </code></pre>
  
  <p>and here is the test DbContext:</p>
  
  <pre><code>using System.Data.Entity;
  
  namespace WebApplication1.Models
  {
      public class DogsContext : DbContext
      {
          public DogsContext() : base() { }
  
          public DbSet&lt;Dog&gt; DogNames { get; set; }
      }
  }
  </code></pre>
  
  <p>============= Original Details of Question ==================</p>
  
  <p>SQLite 1.0.91.0 was released yesterday (<a href="http://system.data.sqlite.org/index.html/doc/trunk/www/news.wiki">http://system.data.sqlite.org/index.html/doc/trunk/www/news.wiki</a>) with "Add support for Entity Framework 6". There is a caveat in the included 'Readme' that has you add the following to the following to web.config/app.config:</p>
  
  <pre><code>&lt;configuration&gt;
  &lt;system.data&gt;
      &lt;DbProviderFactories&gt;
          &lt;remove invariant="System.Data.SQLite" /&gt;
          &lt;add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite"
               type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" /&gt;
      &lt;/DbProviderFactories&gt;
  &lt;/system.data&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>If you use NuGet in VS2013 to add "System.Data.SQLite (x86/x64)", you now get this line added to web.config/app.config:</p>
  
  <pre><code>&lt;entityFramework&gt;
  ...
  &lt;providers&gt;
  &lt;provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" /&gt;
  &lt;/providers&gt;
  ...
  &lt;/entityFramework&gt;
  </code></pre>
  
  <p>As a test, I made a copy of a working NET4.5.1/MVC4/EF5/System.Data.SQlite 1.0.90 application and ran PM: update-package on it. It successfully added the above line to my web.config and I added the required "DbProviderFactories" pieces. Rebuild and run... Fail with 'no provider found'. I try it without the "DbProviderFactories"... Fail with 'no provider found'. I remove the new "provider" piece... Fail with 'no provider found'. So I try a new project but with and without Identity (OWIN) in case that is the problem. Neither work... Pretty much run out of ideas, so asking here after Google/StackOverflow searches.</p>
  
  <p>============ 14 Feb 2014 ===============</p>
  
  <p>Unfortunately the changed entries and numerous variations did not work on my PC...
  I am using VS 2013 Pro on Win8.1 Pro x64.
  I reinstalled System.Data.SQLite.
  At least I am getting a new error with both the existing SQLite database and the new one that VS2013 created (which I can access and see it has a proper structure with zero tables):</p>
  
  <pre><code>"An error occurred connecting to the database. The database might be unavailable. An 
  exception of type 'System.Data.Entity.Core.ProviderIncompatibleException' occurred. The 
  error message is: Schema specified is not valid. Errors: StoreSchemaDefinition(2,64) : 
  Error 0175: The ADO.NET provider with invariant name 'System.Data.SQLite.EF6' is either 
  not registered in the machine or application config file, or could not be loaded. See the 
  inner exception for details.'"
  </code></pre>
  
  <p>Both EF6 and System.Data.SQLite (x86/x64) where pulled in via NuGet into brand new MVC Web apps and a Windows Console app. Both produced the above error... I am beginning to suspect that maybe something is wrong with my VS3013 but I do not want to spend another 6 hours downloading and patching it when I can work with MVC4/SQLite/EF5...</p>
  
  <p>===== 17 Feb 2014 ========</p>
  
  <p>@Jimi - No luck here. I tried with NET 4.5 and 4.5.1 with a new MVC and Windows Application Project. I tried with EF6.0.0 and EF6.0.2. I tried replacing the 3x SQLite.Data.xxx.dll refs with local copies from the install of System.Data.SQLite after adding "System.Data.SQLite (x86/x64)" from NuGet . I also tried the NuGet “System.Data.SQLite.MSIL” package instead of adding DBFactories to the various versions of Web.Config and App.Config that I tried.</p>
  
  <p>I also tried creating an NET 4.0 MVC4 Web Application but it appears NuGet’s "System.Data.SQLite (x86/x64)" now includes a requirement for EF6. Being hopeful, I went along with it and tried the various ‘save/create new connection/edit web.config/etc’ but it would not work. I have given up for now and gone back to SQLite with Datasets so I can use Linq with System.Data.DataSetExtensions by making the DataTables "AsEnumerable" (or Java (jdbc) for people that want an offline copy of the database on their Android OS devices with a minimal App interface).</p>
  
  <p>========= 19 Feb 2014 =======</p>
  
  <p>@Christian Sauer - I did not get EF6 and System.Data.SQLite (or System.Data.SQLite.EF6) to work together, yet... but</p>
  
  <p>I just found an update on <a href="http://system.data.sqlite.org/index.html/tktview?name=7b8fd3ef77">http://system.data.sqlite.org/index.html/tktview?name=7b8fd3ef77</a> that says there is a newer SQLite NuGet package:</p>
  
  <pre><code>mistachkin added on 2014-02-19 03:39:35:
  
  All NuGet packages have been updated to 1.0.91.3.  Several fixes are included
  that pertain to supporting Entity Framework 6.
  </code></pre>
  
  <p>I am testing it now with a new Project (MVC Web Project in VS2013 using EF6.0.2 and SQLite 1.0.91.3 that targets .NET 4.5.1)...</p>
  
  <p>No luck again with the new SQLite 1.0.91.3. The web.config has changed to:</p>
  
  <pre><code>  &lt;entityFramework&gt;
      &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"&gt;
        &lt;parameters&gt;
          &lt;parameter value="v11.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" /&gt;
        &lt;add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" /&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;/DbProviderFactories&gt;
   &lt;/system.data&gt;
  </code></pre>
  
  <p>I am going to try messing with the config after work (as suggested by Jimi and PCMB) and post any findings.</p>
  
  <p>I just tried re-installing both the 32 and then the 64 bit versions of System.Data.SQLite (with and without adding to GAC) but EF6 will not work with SQLite. If I try to manually build the model and mappings, it fails any time I reference/try to use EF6. As for creating Entity Data Models (be it generate from existing SQLite or new SQLite database) it will fail/error out no matter what I do to configs, connections or providers.</p>
  
  <p>=========== 22 Feb 2014 =============</p>
  
  <p>They pulled/rolled-back the System.Data.SQLite 1.0.91.3 update to 1.0.91.0. There is still an outstanding ticket (<a href="http://system.data.sqlite.org/index.html/tktview?name=7b8fd3ef77">http://system.data.sqlite.org/index.html/tktview?name=7b8fd3ef77</a>) open that includes some suggestions by mistachkin. Here is the app.config mistachkin recommended trying (this config did not work for me either before or...):</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &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" /&gt;
    &lt;/configSections&gt;
    &lt;system.data&gt;
      &lt;DbProviderFactories&gt;
       &lt;remove invariant="System.Data.SQLite" /&gt;
       &lt;add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" /&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, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" /&gt;
      &lt;/DbProviderFactories&gt;
    &lt;/system.data&gt;
    &lt;connectionStrings&gt;
      &lt;add name="northwindEFEntities" connectionString="metadata=res://*/NorthwindModel.EF6.2013.csdl|res://*/NorthwindModel.EF6.2013.ssdl|res://*/NorthwindModel.EF6.2013.msl;provider=System.Data.SQLite.EF6;provider connection string=&amp;quot;data source=.\northwindEF.db&amp;quot;" providerName="System.Data.EntityClient" /&gt;
    &lt;/connectionStrings&gt;
    &lt;entityFramework&gt;
      &lt;providers&gt;
       &lt;provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" /&gt;
      &lt;/providers&gt;
    &lt;/entityFramework&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>after I tried mistachkin's suggestion to add the dll's to the GAC (done with .NET "gacutil.exe")...</p>