LinqCompose 0.2.5

dotnet add package LinqCompose --version 0.2.5
                    
NuGet\Install-Package LinqCompose -Version 0.2.5
                    
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="LinqCompose" Version="0.2.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LinqCompose" Version="0.2.5" />
                    
Directory.Packages.props
<PackageReference Include="LinqCompose" />
                    
Project file
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 LinqCompose --version 0.2.5
                    
#r "nuget: LinqCompose, 0.2.5"
                    
#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 LinqCompose@0.2.5
                    
#: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=LinqCompose&version=0.2.5
                    
Install as a Cake Addin
#tool nuget:?package=LinqCompose&version=0.2.5
                    
Install as a Cake Tool

LinqCompose

latest version

LinqCompose is a library that aims to simplify abstracting and composing LINQ operations,

Features:

  • Generating expressions for selecting only required properties, based on a mapping expression.
  • Substituting expression placeholders in an expression.

Installation

dotnet add package LinqCompose

Examples

EF Core projection from a mapping

The primary use case for generating property selection expressions from a mapping, is to use with IQueryable<T>.Select when querying with Entity Framework. This effectively allows Entity Framework to only fetch the database columns that are actually used. This is generally trivial do by hand but can become tedious when trying abstract the actualy querying out into a service.

class QueryService(DbContext context) 
{
    public List<T> GetEntityListAs<T>(Expression<Func<Entity, T>> mapping)
    {
        var entities = context.Entities
            .Where(x => /* some condition */)
            // Fetch fields required by mapping, but also ensure Id and RelevantProperty are fetched
            .IncludeDependenciesOf(mapping, e => new { e.Id, e.RelevantProperty })
            .ToList();
        
        // Perform any necessary computations/queries using relevant fetched properties.
        
        var m = mapping.compile();
        return entities.Select(m).ToList();
    }
}

class Service(QueryService queryService) 
{
    public void DoSomething() 
    {
        var data = queryService.GetEntityListAs(e => new { e.Name, e.PropA, e.RelatedEntity.PropB });
        // Do something with the data...
    }
}

Reusing expression segments in other expressions

One challenge when working with Entity Framework and LINQ expressions is reusing logic that needs to be consistent across many queries. Entity Framework Core largely is not able to translate queries that include function calls (that aren't sufficiently parametrized) in them.

On top of that, expressions representing functions cannot be called inside an expression. LinqCompose aims to provide a means to achieve by means of a substitution expressions:

using static LinqCompose.Composer;
Expression<Func<int, bool>> reusableExpression = x => x > 10;
var substitutedExpression = Compose<SomeObject, bool>(obj => Inline(reusableExpression)(obj.NumericValue));
// substituedExpression will be equivalent to the expression : b => b.NumericValue > 10

The Compose function generally requires explicit type parameters, as inference is insufficient here. There are shorthand definitions for 1-3 parameter functions, but beyond this the full delegate type must be specified. E.g.:

  • Non-shorthand version: Compose<Func<A,B,C,D,ReturnType>>((a,b,c,d) => ...).
  • 2-parameter shorthand: Compose<A,B,ReturnType>((a, b) => ...)
Product 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.

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
0.2.5 5,084 5/31/2026
0.2.4 461 5/18/2026
0.2.3 111 5/12/2026
0.2.2 118 3/21/2026
0.2.1 1,457 3/20/2026
0.2.0 130 3/19/2026
0.1.0 528 2/26/2026
0.0.1 200 2/24/2026