Saturday, March 31, 2018

Using Entity Framework 6 and SQLite with Visual Studio 2017

The System.Data.SQLite DDEX provider does not support Visual Studio 2017. This post describes how to work with SQLite and Entity Framework 6 in Visual Studio 2017, using the "SQLite Toolbox" DDEX provider for EF6. Notice that this provider only supports the EF 6 Tools, and not other Data Source scenarios, for example Typed DataSets.
  • Install Toolbox
  • Install SQLite in GAC
  • Install SQLite EF provider in project
  • Run EDM Wizard

Install latest Toolbox

Once per Visual Studio edition (daily build at )

Install SQLite in GAC

Once per machine. Download sqlite-netFx46-setup-bundle-x86-2015- (from
Select "Full Installation"
Select: Install the assemblies into the global assembly cache - Install VS designer components
Restart Visual Studio
Verify that the EF6 provider is installed in GAC from the Toolbox "About" dialog:
If the EF6 provider is not in GAC, this may be due to an invalid entry in machine.config, located in the C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Config folder. The only SQLite related entry should look like this, with this exact version number:
        <add name="SQLite Data Provider" 
             description=".NET Framework Data Provider for SQLite" 

Install System.Data.Sqlite NuGet package

Install using Package Manager Console or NuGet Manager in each project.
PM> Install-Package System.Data.SQLite
Make sure to install the same version as the tools package above.
Build project!
Packages.config should look like this after install:

  <package id="EntityFramework" version="6.2.0" targetFramework="net461" />
  <package id="System.Data.SQLite" version="" targetFramework="net461" />
  <package id="System.Data.SQLite.Core" version="" targetFramework="net461" />
  <package id="System.Data.SQLite.EF6" version="" targetFramework="net461" />
  <package id="System.Data.SQLite.Linq" version="" targetFramework="net461" />
App.config should look like this:
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
      <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" />

Run Entity Data Model Wizard

Add, New Item, Data, ADO.NET Entity Data Model. Choose "EF Designer from Database" or "Code First from Database"
Use "SQLite Provider (Simple for EF6 by ErikEJ)" when creating a connection to your SQLite database file.

Wednesday, January 4, 2017

Downloading SQL Server Compact 3.5 SP2 for Devices

A number of developers are still, in 2017, developing new solutions for Windows CE / Windows Mobile using Visual Studio 2008 and SQL Server Compact 3.5 SP2. Unfortunately, Microsoft has removed the official download of the SQL CE 3.5 SP2 package for devices, which contains the cab files for installing the SQL CE runtime on various processor flavors of Windows CE / Windows Mobile and also contains a cab file for installing a System.Data.SqlClient (ADO.NET provider for SQL Server), that allows you to access SQL Server directly from a Windows Mobile device.

In this blog post I will describe the steps required to get the Device MSI installed on your development PC. Luckily, it is still currently possible to request the latest updates/hotfixes of the 3.5 SP2 runtime – I have a comprehensive list here.

We can take advantage of the fact, that each “patch” is essentailly a full release of all applicable packages, and that build 8109 is a full re-release of all possible packages.

1: Navigate to the KB page for hotfix 8109:

2: Click the “Hotfix Download Available” link (blue button)

3: Accept the license agreemnt if prompted

4: Expand the list of hotfixes to show all 52 packages by clicking the link “Show hotfixes for all platforms and languages” (this text may be localized)

5: Select (put a checkmark next to) the file named: SSCEDeviceRuntime_ENU

6: Enter your email twice, and press the “Request hotfix” button (button text may be localized)

7: You will now receive an email with a link to the hotfix, download the linked file, named: 465553_ENU_ce_zip.exe

8: Double click the file, and extract it’s compressed contents:

9: Double click  SSCEDeviceRuntime-ENU.msi  to install the Devices SDK:


10: Complete the setup, the cab files are now present in the C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v3.5\Devices folder

Wednesday, December 14, 2016

Entity Framework Core Extensions

This is a list of some of the available Entity Framework Core extensions out there that expand the functionality of the Entity Framework Core runtime. Only libraries that extend DbContext or similar are included, and they must be published on

The EF team has lists of third party EF Core providers here:

For a similar list of EF 6.x extensions, see my blog post here

Please let me know if I have missed anything, and I will add it to the list.


Entity Framework Core Second Level Caching Library.

Second level caching is a query cache. The results of EF commands will be stored in the cache, so that the same EF commands will retrieve their data from the cache rather than executing them against the database again.

Install-Package EFSecondLevelCache.Core


Loads and saves entire detached entity graphs (the entity with their child entities and lists). Inspired by GraphDiff. The idea is also add some plugins to simplificate some repetitive tasks, like auditing and pagination.

Install-Package EntityFrameworkCore.Detached –Pre


Add triggers to your entities with insert, update, and delete events. There are three events for each: before, after, and upon failure.

Install-Package EntityFrameworkCore.Triggers


Reactive extension wrappers for hot observables of Entity Framework entities.

Install-Package EntityFrameworkCore.Rx


Retrieve the primary key (including composite keys) from any entity as a dictionary.

Install-Package EntityFrameworkCore.PrimaryKey 


Get typed access to the OriginalValues of your entity properties. Simple and complex properties are supported, navigation/collections are not.

Install-Package EntityFrameworkCore.TypedOriginalValues


Attempt to capture some good or best practices in an API that supports testing – including a small framework to scan for N+1 queries

Install-Package EFCore.Practices

Sunday, August 28, 2016

In the meantime

Since may last post in February, as few things have happended in the world of Microsoft Data Acces Development:

Entity Framework Core 1.0 has been released at the end of May, including the providers for SQL Server Compact 4.0 and 3.5 (supplied by yours truly). I plan to blog in more detail about using EF Core with this new provider.

A useful SQLite  NuGet package has been released, for use with the .NETStandard 1.0 portable platform.

SQL Server 2016 was released, many highlights and improvements to the relational engiene, as highlighted in the “It just runs faster” blog series.

And SQL Server 2016 Developer Edition is now free (was 50 USD earlier)!

Friday, February 12, 2016

SQL Server Compact 4.0 SP1 hotfix available

I was recently made aware that a hotfix for SQL Server Compact was made available in 2014 –  but better late than never.

The hotfix can be requested via the Microsoft support knowledgebase here:

The file/build version of the hotfix is: 4.0.8902.0 (The .NET assembly version stays at either (or for the “Private” .NET Assembly)

The hotfix includes the following fixes:

FIX: Unexpected ordering when you run ORDER BY statement on a column that contains "-" in SQL Server Compact 4.0

FIX: "ConnectionString cannot be null" when you use folder redirection with offline files

FIX: It takes longer time than flush interval to flush committed transactions in SQL Server Compact 4.0