BlazarTech.QueryableValues.SqlServer 5.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package BlazarTech.QueryableValues.SqlServer --version 5.1.0
NuGet\Install-Package BlazarTech.QueryableValues.SqlServer -Version 5.1.0
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="BlazarTech.QueryableValues.SqlServer" Version="5.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BlazarTech.QueryableValues.SqlServer --version 5.1.0
#r "nuget: BlazarTech.QueryableValues.SqlServer, 5.1.0"
#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 BlazarTech.QueryableValues.SqlServer as a Cake Addin
#addin nuget:?package=BlazarTech.QueryableValues.SqlServer&version=5.1.0

// Install BlazarTech.QueryableValues.SqlServer as a Cake Tool
#tool nuget:?package=BlazarTech.QueryableValues.SqlServer&version=5.1.0

QueryableValues CI/CD Workflow

This library improves the efficiency of some types of queries in Entity Framework Core when using the SQL Server Database Provider.

The provided AsQueryableValues extension method on the DbContext class allows us to efficiently compose an IEnumerable<T> in our queries when it consist of non-constant values. It returns an IQueryable<T> that in the context of a query can be treated as any other entity in our DbContext. Everything is evaluated on the server.

The supported types for T are: Int32, Int64, Decimal, Double, DateTime, DateTimeOffset, Guid, and String.

For a detailed explanation, please continue reading here.

When Should I Use It?

The AsQueryableValues extension method is intended for queries that are dependent on a non-constant sequence of external values. In this case, the underline SQL query will be efficient on subsequent executions.

Getting Started

Installation

QueryableValues is distributed as a NuGet Package. The major version number of this library is aligned with the version of Entity Framework Core that's supported by it; for example, if you are using EF Core 5, then you must use version 5 of QueryableValues.

Please choose the appropriate command below to install it using the NuGet Package Manager Console window in Visual Studio:

EF Core Command
3.x Install-Package BlazarTech.QueryableValues.SqlServer -Version 3.1.0
5.x Install-Package BlazarTech.QueryableValues.SqlServer -Version 5.1.0
6.x Install-Package BlazarTech.QueryableValues.SqlServer -Version 6.1.0

Configuration

Look for the place in your code where you are setting up your DbContext and calling the UseSqlServer extension method, then use a lambda expression to access the SqlServerDbContextOptionsBuilder provided by it. It is on this builder that you must call the UseQueryableValues extension method, as shown in the following simplified examples:

When using the OnConfiguring method inside your DbContext:

using BlazarTech.QueryableValues;

public class MyDbContext : DbContext
{
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseSqlServer(
            "MyConnectionString",
            sqlServerOptionsBuilder =>
            {
                sqlServerOptionsBuilder.UseQueryableValues();
            }
        );
    }
}

When setting up the DbContext at registration time using dependency injection:

using BlazarTech.QueryableValues;

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContext<MyDbContext>(optionsBuilder => {
            optionsBuilder.UseSqlServer(
                "MyConnectionString",
                sqlServerOptionsBuilder =>
                {
                    sqlServerOptionsBuilder.UseQueryableValues();
                }
            );
        });
    }
}

How Do I Use It?

The AsQueryableValues extension method is provided by the BlazarTech.QueryableValues namespace, therefore, you must add the following using directive to your source code file in order for it to appear as a method of your DbContext instance.

using BlazarTech.QueryableValues;

Below are two patterns that you can use to retrieve data from an entity based on values provided by an IEnumerable<T>.

Using the Contains LINQ method

// Sample values.
IEnumerable<int> values = Enumerable.Range(1, 10);

// Example #1 (LINQ method syntax)
var myQuery1 = dbContext.MyEntities
    .Where(i => dbContext
        .AsQueryableValues(values)
        .Contains(i.MyEntityID)
    )
    .Select(i => new
    {
        i.MyEntityID,
        i.PropA
    });

// Example #2 (LINQ query syntax)
var myQuery2 = 
    from i in dbContext.MyEntities
    where dbContext
        .AsQueryableValues(values)
        .Contains(i.MyEntityID)
    select new
    {
        i.MyEntityID,
        i.PropA
    });

Using the Join LINQ method

// Sample values.
IEnumerable<int> values = Enumerable.Range(1, 10);

// Example #1 (LINQ method syntax)
var myQuery1 = dbContext.MyEntities
    .Join(
        dbContext.AsQueryableValues(values),
        i => i.MyEntityID,
        v => v,
        (i, v) => new
        {
            i.MyEntityID,
            i.PropA
        }
    );

// Example #2 (LINQ query syntax)
var myQuery2 = 
    from i in dbContext.MyEntities
    join v in dbContext.AsQueryableValues(values) on i.MyEntityID equals v 
    select new
    {
        i.MyEntityID,
        i.PropA
    });

Do You Want to Know More? 📚

Please take a look at the repository here.

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 netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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
8.1.1 14,356 2/8/2024
8.1.0 7,396 12/7/2023
8.0.0 1,647 11/26/2023
7.4.3 754 2/8/2024
7.4.2 1,217 12/7/2023
7.4.1 6,082 11/26/2023
7.4.0 36,239 6/25/2023
7.3.0 3,515 5/20/2023
7.2.0 3,638 3/27/2023
7.1.0 2,275 3/14/2023
7.0.0 15,164 11/13/2022
7.0.0-preview.2 163 9/3/2022
7.0.0-preview.1 129 8/7/2022
6.9.3 520 2/8/2024
6.9.2 3,229 12/7/2023
6.9.1 121 11/26/2023
6.9.0 8,359 6/25/2023
6.8.0 99,088 5/20/2023
6.7.0 2,731 3/27/2023
6.6.0 559 3/14/2023
6.5.0 80,090 9/3/2022
6.4.0 4,758 7/14/2022
6.3.0 11,494 1/4/2022
6.2.0 324 12/27/2021
6.1.0 300 12/9/2021
6.0.0 989 12/6/2021
5.9.3 89 2/8/2024
5.9.2 124 12/7/2023
5.9.1 109 11/26/2023
5.9.0 142 6/25/2023
5.8.0 150 5/20/2023
5.7.0 203 3/27/2023
5.6.0 279 3/14/2023
5.5.0 1,057 9/3/2022
5.4.0 930 7/14/2022
5.3.0 29,833 1/4/2022
5.2.0 300 12/27/2021
5.1.0 319 12/9/2021
5.0.0 311 12/6/2021
3.9.3 74 2/8/2024
3.9.2 98 12/7/2023
3.9.1 90 11/26/2023
3.9.0 175 6/25/2023
3.8.0 144 5/20/2023
3.7.0 228 3/27/2023
3.6.0 224 3/14/2023
3.5.0 432 9/3/2022
3.4.0 438 7/14/2022
3.3.0 1,389 1/4/2022
3.2.0 267 12/27/2021
3.1.0 297 12/9/2021
3.0.0 381 12/6/2021