FluentSqlKata 2.0.1
dotnet add package FluentSqlKata --version 2.0.1
NuGet\Install-Package FluentSqlKata -Version 2.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FluentSqlKata" Version="2.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FluentSqlKata" Version="2.0.1" />
<PackageReference Include="FluentSqlKata" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FluentSqlKata --version 2.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: FluentSqlKata, 2.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FluentSqlKata@2.0.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FluentSqlKata&version=2.0.1
#tool nuget:?package=FluentSqlKata&version=2.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
FluentSqlKata
Simple and very concrete, fluent way to build sql queries.
Features
- Fluent queries (you have more freedom than with
Linq,HQLorQueryOver) - OrderByAlias (Dynamic way to order by aliases at runtime)
- Can be easily used along with Entity Framework Core without huge code changes (see FluentSqlKata.EFCore)
- All standard SqlKata features remain without changes
Notes
- Select, raw and aggregate aliases must be unique within the same query; a duplicate registration throws an
ArgumentExceptionnaming the conflicting alias. - The raw set-operation helpers (
CombineRawFormat,UnionRawFormat,ExceptRawFormat,IntersectRawFormat) append the raw SQL verbatim; the keyword/operator (e.g.UNION) must be part of the raw statement. FromRaw/FromRawFormatdo not wrap the expression in parentheses; include them in the raw SQL when required.- For
Queryinstances, SqlKata's own instance methods (SelectCount,GroupByRaw, ...) take precedence over same-named fluent extensions when the call shape matches.
Installation
Using dotnet cli
$ dotnet add package FluentSqlKata
Using Nuget Package Manager
PM> Install-Package FluentSqlKata
How to use
using FluentSqlKata;
[Fact]
public void Basic()
{
Customer myCust = null;
(string CustomerId, string CustomerName) result = default;
var query = FluentQuery.Query()
.From(() => myCust)
.Select(() => result.CustomerId, () => myCust.Id)
.Select(() => result.CustomerName, () => myCust.Name)
;
var query_str = new SqlServerCompiler().Compile(query).ToString();
Assert.NotNull(query_str);
Assert.Equal("SELECT [myCust].[Id] AS [Item1], [myCust].[Name] AS [Item2] FROM [Customer] AS [myCust]", query_str);
}
[Fact]
public void Where()
{
Customer myCust = null;
(string CustomerId, string CustomerName) result = default;
var query = FluentQuery.Query()
.From(() => myCust)
.Select(() => result.CustomerId, () => myCust.Id)
.Select(() => result.CustomerName, () => myCust.Name)
.Where((q) => q.Where(() => myCust.Name, "John").OrWhereContains(() => myCust.Name, "oh"))
;
var query_str = new SqlServerCompiler().Compile(query).ToString();
Assert.NotNull(query_str);
Assert.Equal("SELECT [myCust].[Id] AS [Item1], [myCust].[Name] AS [Item2] FROM [Customer] AS [myCust] WHERE ([myCust].[Name] = 'John' OR LOWER([myCust].[Name]) like '%oh%')", query_str);
}
[Fact]
public void Join()
{
Contact myCont = null;
Customer myCust = null;
(string FirstName, string LastName, string CustomerId, string CustomerName) result = default;
var query = FluentQuery.Query()
.From(() => myCont)
.Join(() => myCust, () => myCust.Id, () => myCont.CustomerId)
.Select(() => result.FirstName, () => myCont.FirstName)
.Select(() => result.LastName, () => myCont.LastName)
.Select(() => result.CustomerId, () => myCont.CustomerId)
.Select(() => result.CustomerName, () => myCust.Name)
;
var query_str = new SqlServerCompiler().Compile(query).ToString();
Assert.NotNull(query_str);
Assert.Equal("SELECT [myCont].[FirstName] AS [Item1], [myCont].[LastName] AS [Item2], [myCont].[contact_customer_id] AS [Item3], [myCust].[Name] AS [Item4] FROM [Contacts] AS [myCont] \nINNER JOIN [Customer] AS [myCust] ON [myCust].[Id] = [myCont].[contact_customer_id]", query_str);
}
[Fact]
public void JoinBuilder()
{
Contact myCont = null;
Customer myCust = null;
(string FirstName, string LastName, string CustomerId) result = default;
var query = FluentQuery.Query()
.From(() => myCont)
.Join(() => myCust, (join) => join.WhereColumns(() => myCust.Id, () => myCont.CustomerId))
.Select(() => result.FirstName, () => myCont.FirstName)
.Select(() => result.LastName, () => myCont.LastName)
.Select(() => result.CustomerId, () => myCust.Id)
;
var query_str = new SqlServerCompiler().Compile(query).ToString();
Assert.NotNull(query_str);
Assert.Equal("SELECT [myCont].[FirstName] AS [Item1], [myCont].[LastName] AS [Item2], [myCust].[Id] AS [Item3] FROM [Contacts] AS [myCont] \nINNER JOIN [Customer] AS [myCust] ON ([myCust].[Id] = [myCont].[contact_customer_id])", query_str);
}
[Fact]
public void GroupBy()
{
Customer myCust = null;
Contact myCont = null;
(string CustomerName, int ContactCount) result = default;
var query = FluentQuery.Query()
.From(() => myCont)
.Join(() => myCust, (join) => join.WhereColumns(() => myCust.Id, () => myCont.CustomerId))
.SelectCount(() => result.ContactCount, () => myCont.Id)
.Select(() => result.CustomerName, () => myCust.Name)
.GroupBy(() => myCust.Name)
;
var query_str = new SqlServerCompiler().Compile(query).ToString();
Assert.NotNull(query_str);
Assert.Equal("SELECT COUNT(myCont.Id) AS Item2, [myCust].[Name] AS [Item1] FROM [Contacts] AS [myCont] \nINNER JOIN [Customer] AS [myCust] ON ([myCust].[Id] = [myCont].[contact_customer_id]) GROUP BY [myCust].[Name]", query_str);
}
[Fact]
public void OrderBy()
{
Customer myCust = null;
var query = FluentQuery.Query()
.SelectAll(() => myCust)
.OrderByColumn(() => myCust.Name)
;
var query_str = new SqlServerCompiler().Compile(query).ToString();
Assert.NotNull(query_str);
Assert.Equal("SELECT [myCust].[Name] AS [Name], [myCust].[Id] AS [Id] FROM [Customer] AS [myCust] ORDER BY [myCust].[Name]", query_str);
}
[Fact]
public void OrderByAlias()
{
Customer myCust = null;
CustomerModel model = null;
var query = FluentQuery.Query()
.From(() => myCust)
.SelectRawFormat(() => model.Name, "ISNULL({0}, 'Unknown')", () => myCust.Name)
.OrderByAlias(() => model.Name)
;
var query_str = new SqlServerCompiler().Compile(query).ToString();
Assert.NotNull(query_str);
Assert.Equal("SELECT ISNULL(myCust.Name, 'Unknown') AS Name FROM [Customer] AS [myCust] ORDER BY ISNULL(myCust.Name, 'Unknown')", query_str);
}
Nuget
How to contribute
If you have any issues please provide us with Unit Test Example.
To become a contributor please create an issue ticket with such enquiry.
Donations
Donate with Ӿ nano crypto (XNO).
Thank you!
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- 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.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.1 | 169 | 9/8/2026 |
| 2.0.0 | 135 | 9/8/2026 |
| 1.2.1 | 123 | 9/8/2026 |
| 1.2.0 | 137 | 9/8/2026 |
| 1.1.11 | 130 | 9/8/2026 |
| 1.1.10 | 204 | 2/25/2026 |
| 1.1.9 | 309 | 9/11/2025 |
| 1.1.8 | 304 | 9/11/2025 |
| 1.1.7 | 273 | 7/18/2025 |
| 1.1.6 | 649 | 8/28/2024 |
| 1.1.5 | 596 | 4/25/2024 |
| 1.1.4 | 743 | 9/7/2023 |
| 1.1.3 | 411 | 7/10/2023 |
| 1.1.2 | 308 | 6/28/2023 |
| 1.1.1 | 467 | 4/24/2023 |
| 1.1.0 | 422 | 4/5/2023 |
| 1.0.9 | 376 | 4/5/2023 |
| 1.0.8 | 483 | 3/10/2023 |
| 1.0.7 | 432 | 3/9/2023 |
| 1.0.6 | 539 | 2/7/2023 |
Loading failed
