System.Data.SQLite 1.0.91.0 and EF6.0.2 - c#

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?
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):
uninstall-package entityframework -force
restart VS2013 and put the older EF5 on to get VS2013 to generate an EDMX from an existing database:
install-package entityframework -version 5.0.0
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 :/
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:
you make all the Class(es) file(s),
make a connection to an existing SQLite database with tables,
modify the web/app.config to as described by mistachkin in the still outstanding SQLite Trouble Ticket (http://system.data.sqlite.org/index.html/tktview?name=7b8fd3ef77), including faking the cdsl/.ssdl/.msl pieces, and
then manually create all the Entity Models in the Designer in an Empty EDMX before rebuilding the project and then...
your right click on an Entity and choose 'Update from database'...
Sometimes EF/VS2013 will add the .tt/DbContesxt and sometimes they don't. Way too 'hit or miss' :(
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...
<connectionStrings>
<add name="DogsContext" connectionString="Data Source=|DataDirectory|\dogs.s3db;" providerName="System.Data.SQLite" />
</connectionStrings>
<entityFramework>
<providers>
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite" />
<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" />
<remove invariant="System.Data.SQLite.EF6" />
<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" />
</DbProviderFactories>
</system.data>
Here is the test Class (note that I had to change the DogID to Int64 to get it to work with SQLite...):
using System.Data.Entity;
namespace WebApplication1.Models
{
public class Dog
{
public Dog() { }
public Int64 DogID { get; set; }
public string DogName { get; set; }
}
}
and here is the test DbContext:
using System.Data.Entity;
namespace WebApplication1.Models
{
public class DogsContext : DbContext
{
public DogsContext() : base() { }
public DbSet<Dog> DogNames { get; set; }
}
}
============= Original Details of Question ==================
SQLite 1.0.91.0 was released yesterday (http://system.data.sqlite.org/index.html/doc/trunk/www/news.wiki) 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:
<configuration>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite" />
<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" />
</DbProviderFactories>
</system.data>
</configuration>
If you use NuGet in VS2013 to add "System.Data.SQLite (x86/x64)", you now get this line added to web.config/app.config:
<entityFramework>
...
<providers>
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
...
</entityFramework>
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.
============ 14 Feb 2014 ===============
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):
"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.'"
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...
===== 17 Feb 2014 ========
#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.
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).
========= 19 Feb 2014 =======
#Christian Sauer - I did not get EF6 and System.Data.SQLite (or System.Data.SQLite.EF6) to work together, yet... but
I just found an update on http://system.data.sqlite.org/index.html/tktview?name=7b8fd3ef77 that says there is a newer SQLite NuGet package:
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.
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)...
No luck again with the new SQLite 1.0.91.3. The web.config has changed to:
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
<remove invariant="System.Data.SQLite.EF6" />
<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" />
</DbProviderFactories>
</system.data>
I am going to try messing with the config after work (as suggested by Jimi and PCMB) and post any findings.
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.
=========== 22 Feb 2014 =============
They pulled/rolled-back the System.Data.SQLite 1.0.91.3 update to 1.0.91.0. There is still an outstanding ticket (http://system.data.sqlite.org/index.html/tktview?name=7b8fd3ef77) 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...):
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite" />
<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" />
<remove invariant="System.Data.SQLite.EF6" />
<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" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<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="data source=.\northwindEF.db"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<providers>
<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" />
</providers>
</entityFramework>
</configuration>
after I tried mistachkin's suggestion to add the dll's to the GAC (done with .NET "gacutil.exe")...

I worked on this for several hours today before figuring it out. The NuGet package adds the appropriate entry "System.Data.SQLite.EF6" into the EntityFramework provider factories, but you have to remove or comment out the old "System.Data.SQLite" entry. The EF context builder blows up if any of the provider entries are invalid, and the old 1.0.91 SQLite provider is not supported in EF6.
EDIT: Cleaning up the config allowed my other context objects (SQL Server) to instantiate, but it still won't instantiate the SQLite context objects correctly. The inner exception is
Unable to find the requested .Net Framework Data Provider. It may not
be installed.
EDIT 2/SOLUTION
Finally figured it out! I think there's an issue in System.Data.SQLite that is forcing a reference to the System.Data.SQLite provider name rather than the value provided in the connection string. I was able to work around this by creating two entries in the EntityFramework provider section, one named "System.Data.SQlite", and one named "System.Data.SQLite.EF6", but both providers actually use the EF6 provider.
<entityFramework>
...
<providers>
<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" />
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
</providers>

Here is my whole config file. I am running EF 6.0.2 with SQLite 1.0.91. I haven't tried the model generator yet, but my context objects work fine, and I have tested insert/update/delete via the context as well as direct SQL commands via the dbcontext. The trick is in the entityFramework/providers section. I had to duplicate the SQLite provider entries for the EF6 provider, but use the old and new invariant names.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="electra.common.configuration.electraConfiguration" type="Electra.Common.Configuration.ElectraConfiguration, Electra.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" allowDefinition="Everywhere" allowExeDefinition="MachineToApplication" restartOnExternalChanges="true" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
<connectionStrings>
<add name="DBContext_Server"
connectionString="server=sunset\sql2012;Integrated Security=SSPI;database=Electra;Pooling=true;max pool size=1000;min pool size=5;Connection Lifetime=30;connection timeout=15"
providerName="System.Data.SqlClient" />
<add name="DBContext_ElectraPOS"
connectionString="Data Source=D:\Electra\ElectraWeb\PosEngine.Repository\ElectraPOS.db"
providerName="System.Data.SQLite.EF6" />
</connectionStrings>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite" />
<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" />
<remove invariant="System.Data.SQLite.EF6" />
<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" />
</DbProviderFactories>
</system.data>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<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" />
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
</providers>
</entityFramework>
<electra.common.configuration.electraConfiguration>
<logging>
<levels info="true" warning="true" error="true" debug="true" />
</logging>
</electra.common.configuration.electraConfiguration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.2.0" newVersion="2.0.2.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

After 6 hours of trial/error attempts, head banging on the wall and other stuff we devs do figuring out how things work, I believe I managed to have it working on VS 2013.
Follow this steps.
Install System.Data.SQLite if you haven't done so already.
Fetch System.Data.SQLite in your project from NuGet (notice it adds some stuff in the app.config).
This is the important part. Save your solution and exit VS 2013.
Reload the solution and now you can add a ADO.NET Entity Data Model into your project.
Each time you want to add a model you will have to exit VS 2013 and must create the model using "New Connection..."
Why it works this way, you say? The universe works in mysterious ways, I say.
Edit: Working further on it I discovered that in order to open a connection to the model you have to change the provider in the config from <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" /> to <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" /> and DbProviderFactories has to be inside a system.data tag in not in already.

Just want to share with all my experience with the same problem
I tried to use System.Data.SQLite 1.0.94 and EF6 and have some issues with connection to database. I work in VS 2013.4. After installing all necessary packages and cheking web.config as pmbc suggested I still had the same problem with connection and exception of type System.Data.Entity.Core.ProviderIncompatibleException.
After some additional searching in the internet I found this add-on for VS2013 to work with SQL Compact and SQLite Databases which really hepled me: https://visualstudiogallery.msdn.microsoft.com/0e313dfd-be80-4afb-b5e9-6e74d369f7a1
Now I can use exsiting SQLite db/create new one from VS/create EF model using existing db and all other stuff
Hope this helps
UPDATE
Just some more info for help. Here is my resulting .config file section
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.95.0, Culture=neutral" />
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.95.0, Culture=neutral" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite" />
<remove invariant="System.Data.SQLite.EF6" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
<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" />
</DbProviderFactories>
</system.data>
Also check version number of System.Data.SQLite.dll library which you installed locally (by defaulr, it is installed in GAC) Your GAC version and version of package in your current project must be the same. Otherwise you'll catch an exception when you start your app

It worked for me on VS 2010 using a console app and doing code first. In any case here is my app.config, which is based on Brice's EF6 SQLite tutorial (http://www.bricelam.net/2012/10/entity-framework-on-sqlite.html):
<?xml version="1.0"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0"/>
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite" />
<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" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="ChinookContext" connectionString="Data Source=|DataDirectory|Chinook_Sqlite_AutoIncrementPKs.sqlite" providerName="System.Data.SQLite"/>
</connectionStrings>
</configuration>

Finally This Solution Work for me.
DotNet Framewok=4.5.1
Entity framework=6.1.1
Download this :sqlite-netFx451-setup-bundle-x86-2013-1.0.94.0.exe
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<!--<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />-->
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
</entityFramework>
<system.data>
<!--
NOTE: The extra "remove" element below is to prevent the design-time
support components within EF6 from selecting the legacy ADO.NET
provider for SQLite (i.e. the one without any EF6 support). It
appears to only consider the first ADO.NET provider in the list
within the resulting "app.config" or "web.config" file.
-->
<DbProviderFactories>
<remove invariant="System.Data.SQLite" />
<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.94.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
<remove invariant="System.Data.SQLite.EF6" />
<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" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="VelocityDBEntities" connectionString="metadata=res://*/AppData.Model1.csdl|res://*/AppData.Model1.ssdl|res://*/AppData.Model1.msl;provider=System.Data.SQLite.EF6;provider connection string="data source=F:\VelocityPOS\VelocityDB.sqlite"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>

I just set Copy local = True for System.Data.SQLite.EF6 library (in References -> System.Data.SQLite.EF6 -> Property) and it works

After hours spent on digging through internet, here I present a working solution
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<providers>
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
</entityFramework>
<connectionStrings>
<add name="NorthwindContext" connectionString="Data Source=Northwind.sl3" providerName="System.Data.SQLite.EF6" />
</connectionStrings>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite.EF6" />
<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" />
</DbProviderFactories>
</system.data>
</configuration>
project

That works for me :
<entityFramework>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
<!--<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
<remove invariant="System.Data.SQLite" />
<remove invariant="System.Data.SQLite.EF6" />
<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" />-->
</DbProviderFactories>
</system.data>
With the latest nuget package (1.0.94.1) : https://www.nuget.org/packages/System.Data.SQLite/
And SQLite tools : Setups for 32-bit Windows (.NET Framework 4.5.1) at http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki

I experienced the same kind of error, but for a reason which seems to not have been covered by the other answers. So I would like to share my own case.
In the assembly which contains EDMX, everything was ok.
In client (executing) assembly, I had always the same error at runtime (The Entity Framework provider type 'System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SQLite.EF6' could not be loaded.)
I noticed that for EDMX assembly the "Copy local" was set to true, but not in executing assembly. I fixed it, and it was ok.
So if you experience this issue too and you don't have SQLite provider in GAC, check in your references if you have enabled "copy local" for the SQLite DLLs
I lost a long time before to figure at checking provider and a bunch of other things, so I hope it will be helpful for some others !

<providers>
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
</providers>
this worked for me there are some internal errors while it runs probably do the differences between how EF likes to have 2 other tables for code first __MigrationHistory & EdmMetadata. I would call it trivial for now but if you truly want to take advantage of CodeFirst those tables have to be created manually I am assuming for now.
Edit -- Only entry in provider list and I removed all references to SqlServer...
Vs2013 Ultimate lastest SQLite Nuget.

I had a permission issue during the package installation, so I got this error.
i solved running vs2013 as administrator.
so:
unistall the package
close vs2013
run it again as administrator (important)
install the nugetpackage again
in the end i also ad this in the providers (as suggested by the other users):
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />

Here is the solution that worked for me.
Install the System.Data.SQLite package and make sure that the db factories section is like below.
<DbProviderFactories>
<remove invariant="System.Data.SQLite" />
<remove invariant="System.Data.SQLite.EF6" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
<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" />
</DbProviderFactories>

By installing the latest SQLite from Nuget Package manager, I had got an error when installing SQLite packages (while working on a project that needed edmx over sqlite DB).
Step 1: Read the message carefully. It can reveal what the error message is trying to convey.
Eg:
An error occurred while connecting to the database. The database might be unavailable. An exception of type 'System.InvalidCastException' occurred.
The error message is: '[A]System.Data.SQLite.SQLiteConnection cannot be cast to [B]System.Data.SQLite.SQLiteConnection.
Type A originates from 'System.Data.SQLite, Version=1.0.105.1, Culture=neutral, PublicKeyToken=db937bc2d44ff139' in the context 'Default'
at location 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.Data.SQLite\v4.0_1.0.105.1__db937bc2d44ff139\System.Data.SQLite.dll'.
Type B originates from 'System.Data.SQLite, Version=1.0.106.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' in the context 'LoadNeither'
at location 'C:\Users\Ganesh Kamath\AppData\Local\Microsoft\VisualStudio\14.0\ProjectAssemblies\og1mcjvn01\System.Data.SQLite.dll'.'.
After reading this I realized that I had chosen Version 1.0.106.0 for upgrade.
Essentially the message says that it knows version 1.0.105.1 but not version 1.0.106.0.
Step 2: Remove the version causing the problem by manually selecting the occurence in Nuget Package for Solution option in Visual Studio.
Tools > Nuget Package Manager > Manage Nuget Packages for Solution...
Step 3: Use Nuget Command line to install the version of SQLite that the system understands.
In the example above, the version is 1.0.105.1
Tools > Nuget Package Manager > Package Manager Console
The commands needed for this will look like the following:
Install-Package System.Data.SQLite -Version 1.0.105.1
Install-Package System.Data.SQLite.Core -Version 1.0.105.1
Install-Package System.Data.SQLite.EF6 -Version 1.0.105.1

Related

MySQL and MVC Entity Framework in VS 2017 Not Working

I am trying to start an MVC EF Visual Studio 2017 project. I have my Data Connection all set up with MySQL on my local instance but when I go to create an ADO.net Data Model I get the error seen in the picture:
There was another article here: Can't use a MySQL connection for entity framework 6 that covered VS 2012 and 2013 but not 2017. Here is the MySQL documentation that says what versions work with 2017: https://dev.mysql.com/doc/visual-studio/en/visual-studio-install.html
I am using:
MySQL Connector Net 6.9.9 | MySQL for Visual Studio 1.2.7 | MySQL Server 5.7
MySQL.Data 6.9.9 | MySQL.Data.Entity 6.9.9 | Entity Framework 6.1.3
All of which are listed as tested and working by MySQL. I just installed all new everything today so there are no outstanding old versions. I triple checked ;)
Connection string:
<connectionStrings>
<add name="MySQL" connectionString="server=localhost;port=3306;user id=root;password=password;database=localdb" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
Edit
I have found this article https://dev.mysql.com/doc/connector-net/en/connector-net-entityframework60.html that talks about setting up the connection but now instead of that error, the dialog box just goes away as soon as I hit 'Next'.
Is this just me doing something incorrectly or a broken MySQL connector?
Thanks in advance for any advice!
What I had to do was reinstall MySQL for Visual Studio 2.0.5, then completely remove and install MySQL Connector 6.9.9. Seems the order does matter. After that, I completely remove these packages, and reinstalled in this exact order:
(restart Visual Studio afterward)
EntityFramework 6.1.3 (I tried earlier versions and they don't work, so beware)
Mysql.Data 6.9.9
Mysql.Data.Entity 6.9.9 (NOT Mysql.Data.Entities!!! [for 6.9.9])
Mysql.Web 6.9.9
Then, make sure the following is in your web.config file:
(restart after editing to be sure)
<entityFramework>
<defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6" />
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
</providers>
</entityFramework>
(you may have to comment out any existing section and replace it with this one)
The last step I had to remind myself by revisiting here.
That part is what I forgot about (been too long), which caused the error in the screenshot in the question.
One last thing, you may have incorrect versions copied to where Visual Studio is installed; for example:
C:\Program Files (x86)\Microsoft Visual Studio\{Year}\{Community|Enterprise|Professional}\Common7\IDE\PrivateAssemblies
or
C:\Program Files (x86)\Microsoft Visual Studio {Your Version Number}\Common7\IDE\PrivateAssemblies
MySql.Data.dll
MySql.Data.Entity.EF6.dll
MySql.Web.dll
(may have to close Visual Studio first)
You can select each file and go to the Details tab under the file properties to see what versions you have.
Get the new files from here (or wherever you installed it):
C:\Program Files (x86)\MySQL\MySQL Connector Net 6.9.9\Assemblies\v4.5
(this assumes Connector v6.9.9 using framework v4.5 [see your project properties' Application->Target Framework to confirm your setting]).
Note 1: When you install MySQL for Visual Studio, it updates the files in the PrivateAssemblies folder (see the Visual Studio paths above), so PLEASE double check the assemblies above to make sure they didn't get changed to anything other than your target version (6.9.9 in this case). Regardless of what NuGet installs, Visual Studio won't even care, and will look in the private assemblies (I think during startup actually).
Note 2: If you get an "IsPrimaryKey" error, see here.
My completed App.Config that works for reference (to compare with yours):
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<entityFramework>
<defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6" />
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
</providers>
</entityFramework>
<connectionStrings>
<!-- Connections Strings Go Here -->
</connectionStrings>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.9.9.0" newVersion="6.9.9.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
So eventually what I did was I created a new project and did a clean install of MySQL.Data 6.9.9 | MySQL.Data.Entity 6.9.9 | Entity Framework 6.1.3 and then tried to make the data model again.
It almost worked! I got an error saying: 'System.Data.StrongTypingException: The value for column 'IsPrimaryKey' in table 'TableDetails' is DBNull. ---> System.InvalidCastException: Specified cast is not valid. But lots of people have worked past this issue by going into the MySQL command line and executing: set global optimizer_switch='derived_merge=off' You can find this bug here: https://bugs.mysql.com/bug.php?id=79163
For whatever reason this works. here is the output of my command line to as to help any newbies at MySQL:
This fixes EVERYTHING! hopefully someone finds this an doesn't waste as much time as I did.
#James Wilkins Thanks for the detailed answer, I've to add, sometime when you are adding Mysql.data or MySQL.data.entity the assembly version doesn't match the assemblies installed by MySqlConnector/Net, as we often download the latest version from Nuget, this cause this issue again, so what I did and fixed the issue, I copied the dll (Mysql.data, MySQL.data.entity and web) from
C:\Program Files (x86)\MySQL\MySQL Connector Net 6.9.9\Assemblies\v4.5
to my application bin/debug folder and reference these instead of downloading from Nugets. This fixed my issues. You may also need to update the assembly version in app.config or web.config and packages.config file as well.
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.10.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d">
To
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d">
And update the version for the entries here in packages.config
<package id="MySql.Data" version="6.9.9" targetFramework="net452" />
<package id="MySql.Data.Entity" version="6.9.9" targetFramework="net452" />
<package id="MySql.Web" version="6.9.9" targetFramework="net452" />
Tuning in to confirm that I got everything working -including the db-first gui-tool-chain of Entity Framework in VS2017- on a .net 4.7.1 asp.net-mvc5 wev-solution by employing these exact components on Visual Studio 2017 (VS2017 => ver15.5.7 aka fully updated VS2017 at the time of this writing):
Entity Framework ver6.2.0 [nuget]
MySql.Data ver6.9.11 [nuget]
MySql.Data.Entity ver6.9.11 [nuget]
MySql.Web ver6.9.11 [nuget]
MySQL for Visual Studio ver2.0.5 [system-wide msi installer]
MySql-Connector ver6.9.11 [system-wide msi installer]
I tried using the latest MySql-Connector (ver.6.10.x) but it turned out that the gui tools of VS2017 for the db-first approach wouldn't work at all. I guess MySql-Connector has to be aligned with the rest of the dlls version-wise.
Web.config looks like so:
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
[...]
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=.; Integrated Security=True; MultipleActiveResultSets=True;" />
</parameters>
</defaultConnectionFactory>
[...]
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
[...]
</providers>
[...]
</entityFramework>
[...]
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add description=".Net Framework Data Provider for MySQL" invariant="MySql.Data.MySqlClient" name="MySQL Data Provider" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data" />
</DbProviderFactories>
</system.data>
[...]
</configuration>
And the App.config the child project hosting the .edmx file looks like so:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework" requirePermission="false" />
[...]
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
[...]
</providers>
</entityFramework>
[...]
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add description=".Net Framework Data Provider for MySQL" invariant="MySql.Data.MySqlClient" name="MySQL Data Provider" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data" />
</DbProviderFactories>
</system.data>
[...]
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" />
</startup>
</configuration>
And the packages.config:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.2.0" targetFramework="net471" allowedVersions="[6.2.0]" />
<package id="LinqKit" version="1.1.13" targetFramework="net471" allowedVersions="[1.1.13]" />
<package id="MySql.Data" version="6.9.11" targetFramework="net471" allowedVersions="[6.9.11]" />
<package id="MySql.Data.Entity" version="6.9.11" targetFramework="net471" allowedVersions="[6.9.11]" />
<package id="MySql.Web" version="6.9.11" targetFramework="net471" allowedVersions="[6.9.11]" />
</packages>
Note: The packages.config has been tweaked intentionally by means of [allowedVersions] to forbid unintentional auto-upgrades of MySql packages to their more recent versions. This was done due to dodge issues that plague the 6.10.x flavors of the MySql nugets.

SQLite connection not appearing in Entity Data Model Wizard (vs2015)

What I did is,
1) Created a project in vs2015 (.Net Framework 4.6)
2) Installed System.Data.SQLite from Nuget. Actually System.Data.SQLite(1.0.105.1),System.Data.SQLite.Core(1.0.105.1),System.Data.SQLite.EF6(1.0.105.1),System.Data.SQLite.Linq(1.0.105.1),EntityFramework(6.0.0) were installed
3) Updated EntityFramework to 6.1.3 in Nuget
4) Tried to create Entity Data Model from a local Sqlite database
5) Rebuilded the whole solution
But when I tried to create a new database connection, SQLite connection was not appearing in the data source.
Can anyone figure out this issue?
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configsections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
<entityframework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<system.data>
<dbproviderfactories>
<remove invariant="System.Data.SQLite.EF6" />
<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" />
<remove invariant="System.Data.SQLite" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
AFAIK the designer support is not included in the nuget packages of SQLite: you will need to install the package that is indicated for the version of Visual Studio that you are using.
According to the System.Data.SQLite downloads page currently the only package providing designer support in VS 2015 are the Setups for 32-bit Windows (.NET Framework 4.6) sqlite-netFx46-setup-bundle-x86-2015-1.0.105.1.exe (16.93 MiB), which contains the following sentence in its description:
This is the only setup package that is capable of installing the design-time components for Visual Studio 2015.

EntityFramework 6 won't work with MySql

I am trying to use my model and create a database from it. When i try to generate a database based on the model i get the following error:
Running transformation: System.InvalidOperationException: The SSDL generated by the activity called 'CsdlToSsdlAndMslActivity' is not valid and has the following errors:
No Entity Framework provider found for the ADO.NET provider with invariant name 'MySql.Data.MySqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
at Microsoft.Data.Entity.Design.DatabaseGeneration.EdmExtension.CreateAndValidateStoreItemCollection(String ssdl, Version targetFrameworkVersion, IDbDependencyResolver resolver, Boolean catchThrowNamingConflicts)
at Microsoft.VisualStudio.TextTemplatingFED2D73CEED00C99E8A0A14FA9AE33EAFFDF3CAAFEE9E04D21CC913F1C5C88D960592C81A433C11663E61FD5459CF679CFD9B7275B72CA8BFB8D753DBB9FDDE3.GeneratedTextTransformation.get_Store() in C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes\GenerateTSQL.Utility.ttinclude:line 57
at Microsoft.VisualStudio.TextTemplatingFED2D73CEED00C99E8A0A14FA9AE33EAFFDF3CAAFEE9E04D21CC913F1C5C88D960592C81A433C11663E61FD5459CF679CFD9B7275B72CA8BFB8D753DBB9FDDE3.GeneratedTextTransformation.TransformText() in C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\DBGen\SSDLToSQL10.tt:line 84 C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes\GenerateTSQL.Utility.ttinclude 57
The following contains my App.config if that is of any help:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<connectionStrings>
<add name="SomeDatabase" providerName="MySql.Data.MySqlClient" connectionString="password=user;server=192.168.0.114;uid=hello;database=example;persistsecurityinfo=True;" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"></assemblyBinding>
</runtime>
</configuration>
I know the issue is with the MySql.Data.MySqlClientbased on the error message, but i can't seem to figure out what it wants me to do. I have added MySql.Data, MySql.Data.Entity.EF6 and EntityFramework to the project.
Anyone knows how to fix this issue?
I was facing the same problem before this. I manage to solve it by creating a whole new project.
Go to Manage NuGet Packages, install EntityFramework, MySql.ConnectorNET.Data and MySql.ConnectorNET.Entity.
Use the connection string as shown here <add name="SomeDatabase" providerName="MySql.Data.MySqlClient" connectionString="server=localhost;port=3306;database=example;uid=hello;password=user"/>
Add [DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))] in DbContext class.

System.Data.SQLite ADO.NET Provider cannot be loaded on non development machine

I am trying to port an application from EF3.5 using MS-SQL Server to EF6 using SQLite. Currently the application runs fine on my development machine but as soon as I try to deploy it somewhere else (in this case my Installation-Test-VM), it won't load. Instead I get an exception stating that the ADO.NET Provider with the invariant name 'System.Data.SQLite' and the framework provider type 'System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6' could not be loaded.
I get the exception in german, the original text is
Der in der Anwendungskonfigurationsdatei für den ADO.NET-Anbieter mit dem invarianten Namen 'System.Data.SQLite' registrierte Entity Framework-Anbietertyp 'System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6' konnte nicht geladen werden.
I get the same message on the development machine when I remove the SQLite DLLs (System.Data.SQLite.dll and System.Data.SQLite.EF6.dll) from the output directory.
My config file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="EntityFramework.MappingAPI" publicKeyToken="7ee2e825d201459e" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.9" newVersion="6.0.0.9" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<providers>
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite.EF6" />
<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" />
<remove invariant="System.Data.SQLite" />
<add name="SQLite Data Provider"
invariant="System.Data.SQLite"
description=".NET Framework Data Provider for SQLite"
type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>
</configuration>
The connection is build at runtime like this:
EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();
entityBuilder.Provider = "System.Data.SQLite"; //I also tried System.Data.SQLite.EF6, same result
entityBuilder.ProviderConnectionString = new SqlConnectionStringBuilder()
{
DataSource = "sqlite_master.db" //The idea is that the user will later be able to choose which DB to open via a file chooser
}.ConnectionString;
entityBuilder.Metadata = #"res://*/OTDModel.csdl|res://*/OTDModel.ssdl|res://*/OTDModel.msl";
connection = new EntityConnection(entityBuilder.ToString()); //here the exception is thrown
connection.Open();
classThatExtendsDbContext dbContext = new classThatExtendsDbContext(connection);
Both DLLs have Local Copy = True and Specific Version = False set in Visual Studio.
I've also tried to use 32bit DLLs on the VM (VM runs a 32bit Win7, dev machine runs 64bit) from the sqlite-netFx451-binary-bundle-Win32-2013-1.0.99.0 paket. Same result.
Has anyone an idea what could be the cause of that behaviour and how to fix this?
UPDATE
I've dusted off an old development machine which has never been used with SQLite and happens to run Windows 7 64Bit. The application starts without any problem. Now I'm setting up a 64bit VM to see if my problem is limited to 32bit machines.
UPDATE 2
Using a 64Bit VM doesn't work as well. Same error as usual.
I've now managed to fix the problem.
The solution is to manually install the correct Microsoft Visual C++ Runtime Library from https://support.microsoft.com/kb/2019667
This helped on both the 32 and the 64bit VM. I used the 2013-x86 version but I guess that you'd have to use the x64 one, if you compile a 64bit application.

Trouble using SQLite 1.0.92 with Entity Framework 6.1

I'm trying to use Entity Framework with a SQLite database file, but can't make it work.
I'm using Visual Studio 2012, SQLite 1.0.92, and Entity Framework 6.1.
The edmx diagram correctly displays my tables, so I guess the mapping works, but when I try to do :
_Context = new DataContext();
var test = _Context.Set<T>().ToList();
I get the following exception :
No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SQLite'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
As suggested in other SO posts, I tried adding this in my DbContext constructor to make sure the dll is copied :
var ensureDLLIsCopied = System.Data.Entity.SqlServer.SqlProviderServices.Instance;
The result is that instead of throwing and exception, my program just hangs forever.
I aslo tried to change the app.config file as suggested here and in this post's accepted answer, but no changes.
Any ideas?
Thank you
Edit :
I changed my DbContext from this :
public class DataContext : DbContext { }
to this :
public class DataContext : DbContext
{
public DataContext() : base("name=Entities") { }
}
Now, the exception I get is :
Cannot find 'Entities' connection string in the application configuration file
But the 'Entities' connection string is in app.config :
<add name="Entities"
connectionString="metadata=res://*/Entities.Model.csdl|res://*/Entities.Model.ssdl|res://*/Entities.Model.msl;provider=System.Data.SQLite;provider connection string="data source=mypath\dbname.db""
providerName="System.Data.EntityClient" />
Are you sure you have your app.config setup properly? I'm using EF6.1 with System.Data.SQLite v1.0.92.0 using the following app.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
<remove invariant="System.Data.SQLite.EF6" />
<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" />
</DbProviderFactories>
</system.data>
<entityFramework>
<providers>
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
</entityFramework>
</configuration>
This will need to be in the app.config for the executing program not the app.config for the assembly which contains your DbContext. Alternatively you could use code based configuration as I answered here which you can place in the same assembly as your DbContext.
And also yes if your DbContext is in a different assembly then that assembly will need some code referencing SQLite otherwise the compiler won't include the references to the required SQLite assemblies. You've provided an incorrect reference above to SqlServer rather than SQLite which won't work.
if you used System.Data.SQLite v1.0.92.0
Replace the old snippet in Web.config:
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.SQLiteProviderServices, System.Data.SQLite.Linq"/>
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6"/>
Instead of:
<entityFramework>
<providers>
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6"/>
</providers>
It works for me.
The difference is in "invariantName", remove the "EF6".

Categories