SqlKata.EntityFrameworkCore
1.0.7
dotnet add package SqlKata.EntityFrameworkCore --version 1.0.7
NuGet\Install-Package SqlKata.EntityFrameworkCore -Version 1.0.7
<PackageReference Include="SqlKata.EntityFrameworkCore" Version="1.0.7" />
<PackageVersion Include="SqlKata.EntityFrameworkCore" Version="1.0.7" />
<PackageReference Include="SqlKata.EntityFrameworkCore" />
paket add SqlKata.EntityFrameworkCore --version 1.0.7
#r "nuget: SqlKata.EntityFrameworkCore, 1.0.7"
#:package SqlKata.EntityFrameworkCore@1.0.7
#addin nuget:?package=SqlKata.EntityFrameworkCore&version=1.0.7
#tool nuget:?package=SqlKata.EntityFrameworkCore&version=1.0.7
SqlKata.EntityFrameworkCore

A lightweight, fluent integration library that seamlessly connects SqlKata's powerful query builder with Entity Framework's DbContext.
Build complex SQL queries using your existing Entity Framework models without the limitations of LINQ.
Features
- Directly query EF entities using SqlKata's fluent syntax
- Automatic table name resolution from DbContext
- ~Strong typing support for column selection~
- ~Built-in mapping of query results to entity objects~
- ~Transaction support~
- Comprehensive extension methods for DbContext and DbSet
- Performance optimized with minimal overhead
Requirements
- .NET 10 or later
- Entity Framework Core 10 or later
- SqlKata 4 or later
Installation
dotnet add package SqlKata.EntityFrameworkCore
Example without SqlKata.EntityFrameworkCore
Typically, if you're using DbContext, executing a query against your database using SqlKata would look like this:
var QueryCompiler = new SqliteCompiler();
var InsertQuery = new Query("users").AsInsert(new { email = "john.doe@example.com", username = "John", password = "Example123!#", created_at = DateTime.UtcNow, updated_at = DateTime.UtcNow });
var CompiledInsertQuery = QueryCompiler.Compile(InsertQuery);
_ = SomeDbContext.Database.ExecuteSqlRaw(CompiledInsertQuery.Sql, CompiledInsertQuery.Bindings.ToArray());
There are multiple things annoying with this:
- You have to instantiate a compiler, cache it to avoid constantly re-instantiating.
- You have to create a query, and hardcode the table name you're querying against.
- You have to compile the query, save it into a variable, and pass it to ExecuteSqlRaw.
This is WAY too much work for a simple query, and that's exactly where our library comes into play!
Example with SqlKata.EntityFrameworkCore
With our library, all you have to do is:
- Specify which compiler you want to use (only one single time).
- The actual query.
// Specify the compiler that must be used for all future queries.
SqlKataEntityFramework.SetDefaultCompiler<SqliteCompiler>();
// Insert the user.
_ = Db.Database.ExecuteSqlKata(T => T.From(Db.Users).AsInsert(new { email = "jane.doe@example.com", username = "Jane", password = "Example123!#", created_at = DateTime.UtcNow, updated_at = DateTime.UtcNow }));
// Fetching data is even more simple.
_ = Db.Users.FromSqlKata(T => T.Select("*").Where("id", 1)).Single();
// Async variants are available too, with optional cancellation tokens.
_ = await Db.Database.ExecuteSqlKataAsync(T => T.From(Db.Users).AsUpdate(new { username = "Jane Doe" }).Where("id", 1), cancellationToken);
_ = await Db.Users.FromSqlKata(T => T.Where("id", 1)).SingleAsync(cancellationToken);
When the query has no From(...) clause, FromSqlKata uses the table mapped to the DbSet automatically.
License
You are free to use this library however you or your company wants to.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.EntityFrameworkCore (>= 10.0.12)
- Microsoft.EntityFrameworkCore.Relational (>= 10.0.12)
- SqlKata (>= 4.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.