Repository navigation
Home
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.
| 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.
Install the package of your database provider:
dotnet add package Thinktecture.EntityFrameworkCore.SqlServerEnable 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 builderThen 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.
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.
- The rows are in memory, for example in a
List<T>or an array:- Insert only:
ctx.BulkInsertAsync(entities), see Bulk-Insert. - Update only:
ctx.BulkUpdateAsync(entities), see Bulk-Update. - Insert or update:
ctx.BulkInsertOrUpdateAsync(entities), see Bulk-Upsert (Insert-or-Update). - A list with base and derived entities of a table-per-hierarchy mapping: the same methods with one call for the whole list, see Entity Inheritance (TPH).
- Insert only:
- The rows are the result of a LINQ query, and they stay on the database server:
- Insert:
dbSet.BulkInsertAsync(sourceQuery, ...), see Bulk Insert from Query. - Update:
dbSet.BulkUpdateAsync(sourceQuery, ...), see Bulk Update from Query.
- Insert:
- Upsert, or a bulk update followed by a bulk insert: see SQL Server: MERGE statement, result and limits.
- 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.
- Temp-Tables (SQL Server, PostgreSQL, MySQL, SQLite)
- Bulk-Insert (SQL Server, PostgreSQL, MySQL, SQLite)
- Bulk-Update (SQL Server, PostgreSQL, MySQL, SQLite)
- Bulk-Upsert (Insert-or-Update) (SQL Server, PostgreSQL, MySQL, SQLite)
- Entity Inheritance (TPH) in bulk operations and temp tables (SQL Server, PostgreSQL, MySQL, SQLite)
- Truncate Tables (SQL Server, PostgreSQL, MySQL, SQLite)
- Bulk Update from Query (SQL Server, PostgreSQL, MySQL, SQLite)
- Bulk Insert from Query (SQL Server, PostgreSQL, MySQL, SQLite)
Bulk Delete: EF Core natively supports bulk delete via
ExecuteDeleteAsync(). No additional library is needed for this operation.
- Collection Parameters (temp-tables light) (SQL Server, PostgreSQL, MySQL)
- Window Functions Support (RowNumber, Sum, Average, Min, Max) (SQL Server, PostgreSQL, MySQL, SQLite*)
- Bitwise Aggregates (BitOr, BitAnd, BitXor) (PostgreSQL, MySQL)
- Nested (virtual) Transactions
- Table Hints (SQL Server)
- Queries across multiple databases (SQL Server)
- Changing default schema at runtime
- If-Exists / If-Not-Exists checks in migrations (SQL Server, PostgreSQL)
* SQLite supports RowNumber and NTile; Sum, Average, Min, Max are available on SQL Server, PostgreSQL and MySQL.
- Migrations: include-columns (SQL Server, PostgreSQL)
- Migrations: identity column (SQL Server, PostgreSQL)
- Migrations: (non-)clustered PK (SQL Server)
- Temp-Tables
- Bulk-Insert
- Bulk-Update
- Bulk-Upsert (Insert-or-Update)
- Entity Inheritance (TPH) (SQL Server, PostgreSQL, MySQL, SQLite)
- Truncate Tables