22

I have a project that I just updated using nuget. This updated entity framework from 6.1 to 6.1.1, and it updated sqlite to 1.0.93. I wanted to update my model from my latest database. I did the steps of 1) Model from Database 2) Select sqlite database 3) Generate

After the generation I received the following error message shown below. I have the 1.0.93 design time components install. Does anyone know what exactly is causing this error. The project references and versions all match the versions shown above.

Error Message:

Your project references the latest Entity Framework; however and Entity Framework database provider compatible with this version could not be found for you data connection.

Update:

I ended up installing 6.1.0 manually using the package manager console

Install-Package EntityFramework -Version 6.1.0

Then in my csporj files replacing

packages\EntityFramework.6.1.1

with

packages\EntityFramework.6.1.0

I tried creating EF Designer from Database and Code First from Database but I am still getting the same error.

UPDATE

I have followed the instructions Tom has provided, and thanks time for taking the time to respond in depth it is appreciated. But I cannot get the entity framework designer to work with SQLite 1.0.93. What I have found:

1) When I add the SQLite data source from the tools menu as Tom describes I see the SQLite data provider.

Tools > Connect to Data Source

2) But when I restart visual studio the data source is not connected

After restart connection is lost

3) The data source can be refreshed and it is valid after restart

Tables are shown after refresh

4) Add new data item but SQLite is not listed as a provider

SQLite is not listed as a provider

I have double checked the registry and EF6 is appended to the invariant name, the SQLite dlls are registered in the GAC. I will try to see what else I can find but at this point I am not sure what to look for. As a side note I have tried dotConnect and it does not work either with EF 6.1.1.

Update 2

Does anyone know if the Entity Framework Designer has a logging option to find out what might be happening?

dgxhubbard
  • 703
  • 2
  • 7
  • 18

6 Answers6

18

[ UPDATE : for an easier solution that works with Visual Studio 2013 Update 4 (Pro and Ultimate) and recent versions of Sqlite Providers and EF, look at the solution 'broslav' posted below. Don't know if it works with Express editions... ]

Ok, this is a suggestion. This does NOT work for Visual Studio Express editions. Also, I'm not sure how to get it to work for an update of an existing project. And it is an absolute pain in the butt. I haven't tested if everything is required, but this should work:

First, do NOT use the NuGet package for SQLite, but download the assembly installer from here: http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki

Install the Setups for 32-bit Windows (.NET Framework 4.5.1) installer: sqlite-netFx451-setup-bundle-x86-2013-1.0.93.0.exe (10.00 MiB) (NOT the 64-bit version). This is the only one with the designer.

Install and select to install in the GAC and install the Designer for VS13.

For the following, the exact order is important!

I made a video of these steps, see: http://vimeo.com/103372740

Create a project in VS13. Target the build to framework 4.5.1 and x86 explicitly. Save and build.

Next, install the latest EF 6 package (6.1.1) from NuGet. Save and build.

Manually add references to the installed SQLite assemblies (including the Designer) , under the Reference Manager under Assemblies you can find the Extensions option for selecting the four added assemblies in the GAC : System.Data.SQLite Core + Designer + for Entity Framework + for LINQ.. Save and build.

Then create a connection to your database via Connect to Database under Tools. Before you do anything else Save and Build and then RESTART Visual Studio. DO NOT DO ANYTHING ELSE before starting the ADO.NET Entity Data Model wizard, so DO NOT refresh the database connection.

Add an ADO.NET Entity Data Model, select Generate from Database. Your database connection will show up in the drop-down list. Keep it there, but select to create a New Connection anyway and select the exact same database again (as if you are creating a new connection). It sounds silly, but it is crucial, see image below...

Connect Entity Model

When I actually Added an ADO.NET Entity Data Model this way it did present the annoying error, but the Next button is selectable and everything worked regardless (amazingly)!

Designer works, retrieving data and writing data works.

Haven't tested deployment on another machine though... I'm using Win7 64-bit.

CHANGED UPDATE: To get the correct configuration to actually access the database, you have to install the System.Data.SQLite.EF6 package from NuGet after doing all of the above, then add <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" /> to the App.Config and remove the other providers and remove everything in between <system.data></system.data>, otherwise you'll get some exception. But note that this means that every time you want to update the EDMX model, you have to change the App.Config invariantName="System.Data.SQLite" to invariantName="System.Data.SQLite.EF6" and vice versa.

** Is this getting ridiculous? Yes, it is! And it gave me quite a headache... **

TomL
  • 392
  • 1
  • 7
  • I am not familiar with adding a reference via extensions. What does that mean? I have added references via a project too many times to count. – dgxhubbard Aug 11 '14 at 22:36
  • I have created a small console app. I make sure it targets x86 and .net 4.5.1 and build. Close visual studio and reopen visual studio and the project. Then I add the Database first entity data model. The sqlite database selector comes up immediately, no other data providers selection dialog is shown. I select the sqlite database and click next. The dialog disappears and nothing is generated. Not sure what is happening. Also I have added visual studio 2013 update 3. – dgxhubbard Aug 11 '14 at 23:31
  • I built sqlite 1.0.94, with Entity Framework 6.1.1, using registry and gac fixes. Now I am running Entity Framework 6.1.1 and have installed sqlite 1.0.93 (after re-installing windows, visual studio 2013, etc). This whole problem is becoming intractable. – dgxhubbard Aug 11 '14 at 23:36
  • See my additions to the post. Hope it clarifies things. – TomL Aug 12 '14 at 13:56
  • If you try this, follow the instruction to the letter. If I do one little thing different, it doesn't work... So don't forget to first Connect to the Database separately, then restart, then add the ADO.NET Entity Data Model, then connect to the db again in the wizard. See the details above. (let me know if it works for you) – TomL Aug 12 '14 at 14:21
  • I added an update (above) following your excellent instructions. Thanks for all the effort. I cant event see SQLite listed when I try to add the entity data model. – dgxhubbard Aug 12 '14 at 22:35
  • You really really have to follow the instructions EXACTLY! So the datasource should be visible, but should NOT be connected (red x) and you should NOT refresh the database connection before starting the Entity Model wizard and connecting again. It really is a pain to setup, but I've done it a dozen times and it works for me, although maybe it still won't work for you. – TomL Aug 13 '14 at 07:53
  • Worked perfect! Thanks for the instructions. – Frank Aug 30 '14 at 19:46
  • I'm having the same issue as dgxhubbard in that I cannot see the SQLite option when adding the ADO.NET Entity Data Model. The steps given by TomL in the video didn't work for me. I am trying to add SQLite to a VB project. I noticed some of the options in my VS2013 were different. @TomL, what version of VS are you on? – Ben Zuill-Smith Oct 27 '14 at 21:26
  • I tried the same set of steps but it is still not working out for me.....still datasource not showing up in entity model wizard. please help ...i am stucked here since two days now.. – Neha Sep 01 '15 at 12:05
  • is there any command line tools to generate the entities instead of the vs gui? – Lei Yang Jan 02 '20 at 08:25
11

This is what worked for me:

So the packages I had were:

    <packages>
      <package id="EntityFramework" version="6.1.1" targetFramework="net451" />
      <package id="System.Data.SQLite" version="1.0.94.1" targetFramework="net451" />
      <package id="System.Data.SQLite.Core" version="1.0.94.0" targetFramework="net451" />
      <package id="System.Data.SQLite.EF6" version="1.0.94.0" targetFramework="net451" />
      <package id="System.Data.SQLite.Linq" version="1.0.94.1" targetFramework="net451" />
    </packages>

and the app.config that worked for me had contents:

<?xml version="1.0" encoding="utf-8"?>
<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="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <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.diagnostics>
    <sources>
      <!-- This section defines the logging configuration for My.Application.Log -->
      <source name="DefaultSource" switchName="DefaultSwitch">
        <listeners>
          <add name="FileLog" />
          <!-- Uncomment the below section to write to the Application Event Log -->
          <!--<add name="EventLog"/>-->
        </listeners>
      </source>
    </sources>
    <switches>
      <add name="DefaultSwitch" value="Information" />
    </switches>
    <sharedListeners>
      <add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter" />
      <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
      <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
    </sharedListeners>
  </system.diagnostics>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
  </startup>
  <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" />
      <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="WorkinDataEntities" connectionString="metadata=res://*/WorkinDataModel.csdl|res://*/WorkinDataModel.ssdl|res://*/WorkinDataModel.msl;provider=System.Data.SQLite.EF6;provider connection string=&quot;data source=X:\dev\proj\workin\bin\data.db&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

As you can see, somehow in the end, for me, it was not necessary to remove "EF6" from invariantName or to remove or rearrange other providers or default connection factories. I didn't have to do any reg hacks. Rearranging add/remove tags (that were added during NuGet System.Data.SQLite 1.0.94.1 package installation) in the start-up project's app.config made the difference.

After all the above, I updated EntityFramework to 6.1.2 via NuGet and both updating the model from database via designer and accessing the data at runtime still works.

broslav
  • 555
  • 1
  • 5
  • 10
  • 2
    This is a solution that I've also tested on Win 64bit with VisualStudio 2013 Pro Update 4 and the latest Sqlite bundle (1.0.97) en EF. (6.1.3) Works perfectly. And easier as well. Thanks broslav! – TomL Jun 15 '15 at 12:54
  • After failing to get a new Entity Model to see the connection string, I just copied your app config over mine. Viola, the connection string appeared and the entity model was populated with the tables. This was using SQLite 1.0.98.0 and Visual Studio 2015. What a nightmare EF is. Thanks. Need to try and write the steps to how I got it working now ha. – GeoffCoope Sep 17 '15 at 13:12
3

I finally have steps to consistently add Sqlite and EF6 to a project:

EF6: versions 6.0.0 to be 6.1.3 (currently the latest version). System.Data.Sqlite: 1.0.93 - 1.0.95 but not 1.0.98 (currently the latest version).

To avoid getting System.Data.Sqlite 1.0.98 , do not install using Nuget Package manager. Manually install System.Data.Sqlite. Unfortunately, http://system.data.sqlite.org/ does not readily list previous downloads.

x86 System.Data.Sqlite 1.093

x64 System.Data.Sqlite 1.093

I use Nuget Package manager and install EF6 and then I manually added System.Data.Sqlite library. I have tried multiple times to use 1.0.98 but I cannot

App.config File

For my implementation, I am working with database first an manually coding the entity data classes

 public partial class MyDbContextEF : DbContext
{
    public MyDbContext() : base("name=MyDbContext") { }

    public DbSet<DataRecord> DataRecords { get; set; }
}

[Table("TableName")]
public class DataRecord
{
    [Key]
    public Int64 RowID { get; set; }
    public string Name { get; set; }
}
Gary Kindel
  • 17,071
  • 7
  • 49
  • 66
  • I don't know if that's the version or just uninstalling/installing again everything that made the trick but it worked! THanks – dyesdyes Jan 23 '16 at 10:51
2

I reported this issue and a fix is under way, and a workaround appears to be available (I have not tested it) http://system.data.sqlite.org/index.html/tktview?name=e634e330a6

ErikEJ
  • 40,951
  • 5
  • 75
  • 115
  • Thanks Erik. I have been pounding my head against the wall trying to figure this out. I looked at the bug and tried the reg setting mistachkin put in for win 8.1 update 1 64 bit. Alas I still get the same error. But I know it is not my imagination. – dgxhubbard Aug 04 '14 at 23:01
  • I had a feeling the fix would not Work, I will let the sqlite guy know – ErikEJ Aug 05 '14 at 05:29
2

I had the exact same problem--The model designer wizard was not showing my sqlite db in the dropdown list. I was able to resolve it by fiddling with the sqlite db connection and tables.

0a) I added a connection through the Server Explorer to my sqlite file (the sqlite providers and servers showed in new connection wizard for the Server Explorer but not my edmx Model Wizard) 0b) At this point it was not showing in the edmx Model Wizard still, but did show as a Data Connection in the Server Explorer. 1) I added a table to the sqlite file. 2) I closed the connection to the sqlite db through the Server Explorer 3) I opened the design of my dummy table om the sqlite file through the Server Explorer (thus reinitiating the connection) 4) I tried to "Update Model from Database..." and it was showing in the dropdown list

Another step I did not include above was I created and deleted an .mdf SQL server database New Item... > Database Service.... I did that shortly before trying the above steps. I assume that wouldn't matter but you never know.

Not sure what exactly did it. It seemed a manual disconnect and reconnect through the server explorer made VS "wake up" and display the server in the list. Try fiddling with the connection and tables a bit to see if that wakes something up.

Ben Zuill-Smith
  • 3,504
  • 3
  • 25
  • 44
1

I had this problem as well. The cause was probably that I forgot to tick the visual studio checkbox when installing the system.data.sqlite driver and then installed over that with the checkbox ticked without deinstalling the system.data.sqlite driver first. This how I solved it:

  1. Uninstall the system.data.sqlite driver.
  2. Reboot.
  3. Install the system.data.sqlite driver
  4. Delete the old solution and set it up anew, just like you did (might not be necessary).
  5. Add the ADO.NET entity model (the template was missing for me, this answer helped with that)
  6. The sqlite data source should now be available.
Community
  • 1
  • 1
Valakyr
  • 151
  • 1
  • 5