Skip to content
Pawel Gerr edited this page Dec 1, 2026 · 49 revisions

Thinktecture.EntityFrameworkCore

Build NuGet Downloads TestResults

Thinktecture.EntityFrameworkCore.Relational
Thinktecture.EntityFrameworkCore.SqlServer
Thinktecture.EntityFrameworkCore.PostgreSQL
Thinktecture.EntityFrameworkCore.MySql
Thinktecture.EntityFrameworkCore.Sqlite.Core
Thinktecture.EntityFrameworkCore.Sqlite

Thinktecture.EntityFrameworkCore is a set of NuGet packages that extend Entity Framework Core for relational databases. The features are bulk insert, bulk update and bulk upsert of entities, bulk insert and bulk update from a query, temp tables, collection parameters, window functions, bitwise aggregates (PostgreSQL, MySQL), table hints, nested transactions, truncate, queries across databases (tenant databases), the change of the default schema at runtime, and migration helpers. There is no CLI tool and no dotnet tool. The extension methods for application code are in the namespace Thinktecture.

Packages

Package Purpose Depends on Install it directly?
Thinktecture.EntityFrameworkCore.SqlServer Features for SQL Server Thinktecture.EntityFrameworkCore.BulkOperations, Microsoft.EntityFrameworkCore.SqlServer Yes
Thinktecture.EntityFrameworkCore.PostgreSQL Features for PostgreSQL (Npgsql) Thinktecture.EntityFrameworkCore.BulkOperations, Npgsql.EntityFrameworkCore.PostgreSQL Yes
Thinktecture.EntityFrameworkCore.MySql Features for MySQL (MariaDB is not tested) Thinktecture.EntityFrameworkCore.BulkOperations, Microting.EntityFrameworkCore.MySql (MySqlConnector) Yes
Thinktecture.EntityFrameworkCore.Sqlite Features for SQLite, with the native SQLite library Thinktecture.EntityFrameworkCore.Sqlite.Core, Microsoft.EntityFrameworkCore.Sqlite (brings the native SQLite library) Yes
Thinktecture.EntityFrameworkCore.Sqlite.Core The SQLite implementation, without a native SQLite library Thinktecture.EntityFrameworkCore.BulkOperations, Microsoft.EntityFrameworkCore.Sqlite.Core Only for an application that brings its own SQLite build
Thinktecture.EntityFrameworkCore.BulkOperations Provider-independent contracts of the bulk operations, temp tables and collection parameters Thinktecture.EntityFrameworkCore.Relational No, the provider packages reference it
Thinktecture.EntityFrameworkCore.Relational Foundation of all packages Microsoft.EntityFrameworkCore.Relational No, the provider packages reference it

Install one provider package per database provider. The packages SqlServer, PostgreSQL and MySql reference BulkOperations, which references Relational. The package Sqlite references Sqlite.Core, which references BulkOperations.

Getting started

Install the package of your database provider:

dotnet add package Thinktecture.EntityFrameworkCore.SqlServer

Enable the features that you use when you register the DbContext:

using Thinktecture; // required for every extension below

services.AddDbContext<MyDbContext>(builder => builder
   .UseSqlServer(connectionString, sql => sql
      .AddBulkOperationSupport()       // bulk insert/update/upsert, temp tables, truncate
      .AddWindowFunctionsSupport()     // RowNumber, NTile, windowed aggregates
      .AddCollectionParameterSupport() // pass a collection as a query parameter
      .AddTableHintSupport())          // WithTableHints(...), SQL Server only
   .AddNestedTransactionSupport());    // provider-independent, on the outer builder

Then call the feature, for example a bulk insert:

await ctx.BulkInsertAsync(products);

Most features are opt-in and are enabled by a registration method such as AddBulkOperationSupport. The feature pages name the registration of each feature. PostgreSQL, MySQL and SQLite have the same methods on their options builders where the feature exists, see the feature lists in Performance and Features.

Versions and EF Core compatibility

Since version 7.0, the major version of the packages equals the major version of EF Core. Versions 1.x, 2.x, 3.x and 4.x target EF Core 2.2, 3.1, 5 and 6. The column "Provider packages" names the packages without the prefix Thinktecture.EntityFrameworkCore..

Version EF Core Target framework Provider packages Notes
9.x EF Core 9 net8.0, since 9.1.0 also net9.0 SqlServer, Sqlite
10.x EF Core 10 net10.0 SqlServer, Sqlite, Sqlite.Core since 10.0.1, PostgreSQL since 10.1.0, MySql since 10.6.0 TPH support since 10.6.0
11.x EF Core 11 net11.0 SqlServer, PostgreSQL, MySql, Sqlite, Sqlite.Core AddRowNumberSupport and the *.Testing packages are removed

From version 7.3 to 10.x, AddRowNumberSupport is an obsolete alias of AddWindowFunctionsSupport. The packages Thinktecture.EntityFrameworkCore.Testing, .SqlServer.Testing and .Sqlite.Testing exist up to version 10.x. Version 11.0 removed the alias and these packages. This wiki describes the newest version. A difference of an older version is named where it exists.

Choosing the right approach

Writing many rows

Passing a list into a query

  • A list of primitive values in one query: use EF Core's Contains, for example .Where(e => ids.Contains(e.Id)).
  • A join against a list, or a list of objects with several columns: use a collection parameter. It needs no DDL, and it has no index.
  • A primary key or an index is needed, or the set is used in several queries: use a temp table.

The section Collection parameters, table-valued parameters and temp tables compares the three ways.

Performance

Bulk Delete: EF Core natively supports bulk delete via ExecuteDeleteAsync(). No additional library is needed for this operation.

Features

* SQLite supports RowNumber and NTile; Sum, Average, Min, Max are available on SQL Server, PostgreSQL and MySQL.

Convenience

Best Practices

Extensibility

AI Coding Assistants

Clone this wiki locally