BlazarTech.QueryableValues.EF6.SqlServer 1.1.3

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

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

QueryableValues EF6 Edition

MIT License GitHub Stars Nuget Downloads

🤔💭 TLDR; By using QueryableValues, you can incorporate in-memory collections into your EF queries with outstanding performance and flexibility.

This library allows you to efficiently compose an IEnumerable<T> in your Entity Framework 6 (non-core) queries when using the SQL Server Provider. You can accomplish this by using the AsQueryableValues extension method that's available on the DbContext class. The query is processed in a single round trip to the server, in a way that preserves its execution plan, even when the values within the IEnumerable<T> are changed on subsequent executions. The supported types for T are: Byte, Int16, Int32, Int64, Guid, and String.

Highlights

  • ✨ Enables the composition of in-memory data within your queries.
  • 👌 Works with all versions of SQL Server supported by Entity Framework 6.
  • ⚡ Automatically uses the most efficient strategy compatible with your SQL Server instance and configuration.
  • ✅ Boasts over 700 tests for reliability and compatibility, giving you added confidence.

For a detailed explanation of the problem solved by QueryableValues, please continue reading here.

💡 This is a streamlined version of the original QueryableValues for Entity Framework Core, which I have adapted to provide some of its features on Entity Framework 6.

💡 Using Entity Framework Core? Then the original version of QueryableValues is what you need.

When Should You Use It?

The AsQueryableValues extension method is intended for queries that are dependent upon a non-constant sequence of external values. It also enables joins with in-memory data.

Your Support is Appreciated!

If you feel that this solution has provided you some value, please consider buying me a ☕.

Buy me a coffee

Your ⭐ on this repository also helps! Thanks! 🖖🙂

Getting Started

Installation

QueryableValues EF6 Edition is distributed as a NuGet Package. You can install it using the command below in your NuGet Package Manager Console window in Visual Studio:

Install-Package BlazarTech.QueryableValues.EF6.SqlServer

How Do You 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 for it to appear as a method of your DbContext instance:

using BlazarTech.QueryableValues;

💡 If you access your DbContext via an interface, you can also make the AsQueryableValues extension methods available on it by inheriting from the IQueryableValuesEnabledDbContext interface.

💡 You can configure the behavior of QueryableValues EF6 Edition by using the QueryableValuesConfigurator class.

Below are a few examples composing a query using the values provided by an IEnumerable<T>.

Examples

Using the Contains LINQ method:

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

// This intermediary variable is needed to avoid a NotSupportedException
// with the message: "LINQ to Entities does not recognize the method...".
// Seems to be caused by the use of the Contains method.
var qvQuery = dbContext.AsQueryableValues(values);

// Example #1 (LINQ method syntax)
var myQuery1 = dbContext.TestData
    .Where(e => qvQuery.Contains(e.Id))
    .Select(i => new
    {
        i.Id,
        i.GuidValue
    })
    .ToList();
                
// Example #2 (LINQ query syntax)
var myQuery2 = (
    from e in dbContext.TestData
    where qvQuery.Contains(e.Id)
    select new
    {
        e.Id,
        e.GuidValue
    })
    .ToList();

Using the Join LINQ method:

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

// Here we can make direct use of the AsQueryableValues extension without issues.

// Example #1 (LINQ method syntax)
var myQuery1 = dbContext.TestData
    .Join(
        dbContext.AsQueryableValues(values),
        e => e.Id,
        v => v,
        (e, v) => new
        {
            e.Id,
            e.GuidValue
        }
    )
    .ToList();

// Example #2 (LINQ query syntax)
var myQuery2 = (
    from e in dbContext.TestData
    join v in dbContext.AsQueryableValues(values) on e.Id equals v
    select new
    {
        e.Id,
        e.GuidValue
    })
    .ToList();

You can combine multiple set of values in a query:

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

var qvQuery1 = dbContext.AsQueryableValues(values1);
var qvQuery2 = dbContext.AsQueryableValues(values2);

var myQuery = (
    from e in dbContext.TestData
    where
        qvQuery1.Contains(e.Id) ||
        qvQuery2.Contains(e.Id)
    select new
    {
        e.Id,
        e.GuidValue
    })
    .ToList();

You can mix and match these strategies in your query and make them as complex as you like.

That's it!

If you find this work useful please don't forget to ⭐ this repository.

Thanks! 🖖🙂

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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. 
.NET Framework net452 is compatible.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 is compatible.  net48 was computed.  net481 was computed. 
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
1.1.3 14,281 6/10/2023
1.1.2 5,274 12/18/2022
1.1.2-build.41 112 12/18/2022
1.1.1 3,377 11/13/2022
1.1.0 427 10/7/2022
1.0.1 898 9/3/2022
1.0.0 431 9/2/2022
1.0.0-rc.2 107 8/31/2022