How to use SQLite with EF6.
All needed information about SQLite has assembly in site https://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki, and this is another instruction from developer https://github.com/ErikEJ/SqlCeToolbox/wiki/EF6-workflow-with-SQLite-DDEX-provider.
But understanding all of that information is little bit challenge, therefore I try to enumerate main point of this site:
I
-
There are amazing free GUI for SQLlite - https://sqlitestudio.pl/index.rvt. This software is independent from any another software below.
- For any version of Visual is exist amazing extension - SQLite/SQL Server Compact Toolbox. This Toolbox not related to Entity Framework plugins to Visual Studio and working in any version of Visual Studio (not only in VS2015).
-
In 2018 year still nothing Entity Framework design time component further then Visual Studio 2015. This is main point. Because Visual Studio is 32-bit version of program (not X64), fot design time you must to use 32-bit installation. And moreover design-time component must be set to GAC. Component of EF wisard and showing EDMX file not related to SQLite Toolbox SQLite or runtime component.
Any attempt to open EF component in VS2017-VS2019 is finished by crash
- Also there SQLite windows runtime component SQLite for Windows Runtime
-
There four Nuget packages you need to install to each project as runtime component https://www.nuget.org/profiles/SQLite. This is my application.config file:
1: <?xml version="1.0" encoding="utf-8"?>
2: <packages>
3: <package id="EntityFramework" version="6.2.0" targetFramework="net452" />
4: <package id="System.Data.SQLite" version="1.0.111.0" targetFramework="net452" />
5: <package id="System.Data.SQLite.Core" version="1.0.111.0" targetFramework="net452" />
6: <package id="System.Data.SQLite.EF6" version="1.0.111.0" targetFramework="net452" />
7: <package id="System.Data.SQLite.Linq" version="1.0.111.0" targetFramework="net452" />
8: </packages>
II
This is result of SQLite installation to my computer
-
This is my working config of EF6 (SQLite) application.
1: <?xml version="1.0" encoding="utf-8"?>
2: <configuration>
3: <configSections>
4: <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
5: <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
6: </configSections>
7: <startup>
8: <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
9: </startup>
10: <entityFramework>
11: <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
12: <providers>
13: <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
14: <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
15: <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6"/>
16: </providers>
17: </entityFramework>
18: <system.data>
19: <DbProviderFactories>
20: <remove invariant="System.Data.SQLite.EF6" />
21: <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" />
22: <remove invariant="System.Data.SQLite" />
23: <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
24: </DbProviderFactories>
25: </system.data>
26: <connectionStrings>
27: <add name="Url_DB" connectionString="metadata=res://*/UrlDB.csdl|res://*/UrlDB.ssdl|res://*/UrlDB.msl;provider=System.Data.SQLite.EF6;provider connection string="data source=E:\Projects\Resume\Resume\Data\ResumeDB.db"" providerName="System.Data.EntityClient" />
28: </connectionStrings>
29: </configuration>