FluentSqlKata 1.1.6

dotnet add package FluentSqlKata --version 1.1.6                
NuGet\Install-Package FluentSqlKata -Version 1.1.6                
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="1.1.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FluentSqlKata --version 1.1.6                
#r "nuget: FluentSqlKata, 1.1.6"                
#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.
// Install FluentSqlKata as a Cake Addin
#addin nuget:?package=FluentSqlKata&version=1.1.6

// Install FluentSqlKata as a Cake Tool
#tool nuget:?package=FluentSqlKata&version=1.1.6                

FluentSqlKata

Simple and very concrete, fluent way to build sql queries.

Features

  • Fluent queries (you have more freedom than with Linq, HQL or QueryOver)
  • OrderByAlias (Dynamic way to order by columns in runtime)
  • Can be easily used along with Entity Framework Core without huge code changes (see FluentSqlKata.EFCore)
  • All standart SqlKata features remain without changes

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)
        .SelectRaw(() => model.Name, "ISNULL({0}, 'Uknown')", () => myCust.Name)
        .OrderByAlias(() => model.Name)
        ;

    var query_str = new SqlServerCompiler().Compile(query).ToString();

    Assert.NotNull(query_str);
    Assert.Equal("SELECT ISNULL(myCust.Name, 'Uknown') AS Name FROM [Customer] AS [myCust] ORDER BY ISNULL(myCust.Name, 'Uknown')", query_str);
}

Nuget

FluentSqlKata

How to contribute

If you have any issues please provide us with Unit Test Example.

To become a contributer please create an issue ticket with such enqury.

Donations

Donate with Ӿ nano crypto (XNO).

FluentSqlKata Donations

Thank you!

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.1.6 205 8/28/2024
1.1.5 332 4/25/2024
1.1.4 577 9/7/2023
1.1.3 269 7/10/2023
1.1.2 149 6/28/2023
1.1.1 299 4/24/2023
1.1.0 250 4/5/2023
1.0.9 206 4/5/2023
1.0.8 268 3/10/2023
1.0.7 235 3/9/2023
1.0.6 365 2/7/2023
1.0.5 353 1/27/2023
1.0.4 310 1/27/2023
1.0.3 352 1/18/2023
1.0.2 351 12/29/2022
1.0.1 441 8/6/2022
1.0.0 440 8/6/2022
1.0.0-beta1 181 8/3/2022