Linq.Expression.Optimizer
                              
                            
                                1.0.33
                            
                        
                    dotnet add package Linq.Expression.Optimizer --version 1.0.33
NuGet\Install-Package Linq.Expression.Optimizer -Version 1.0.33
<PackageReference Include="Linq.Expression.Optimizer" Version="1.0.33" />
<PackageVersion Include="Linq.Expression.Optimizer" Version="1.0.33" />
<PackageReference Include="Linq.Expression.Optimizer" />
paket add Linq.Expression.Optimizer --version 1.0.33
#r "nuget: Linq.Expression.Optimizer, 1.0.33"
#:package Linq.Expression.Optimizer@1.0.33
#addin nuget:?package=Linq.Expression.Optimizer&version=1.0.33
#tool nuget:?package=Linq.Expression.Optimizer&version=1.0.33
Linq.Expression.Optimizer
Lightweight optimizer of System.Linq.Expression expressions. Just basic boolean algebra and reductions, constant and tuple/anonymous type eliminations. For side-effect-free Expressions. No compilation-subjective optimizations. This is meant to be used with expressions that are not compiled but transferred to other domains.
Supported frameworks: Net 3.5, Net 4.5-... (and Mono), .NET Standard 1.6 (so also .NET Core)
Supported optimizations
Example as a quote. There are various other cases also.
- Replace constants comparisons:    3 < 4 -> true
- Remove anonymous types:    new AnonymousObject(Item1 = x, Item2 = "").Item1 --> x
- Cut not used condition:    if false then x else y -> y
- Remove not:    not(false) -> true
- Binary tree balancing:   a or (b or (c or (d or (e or (f or (g or h)))))) -> ((a or b) or (c or d)) or ((e or f) or (g or h))
- Captured closure constant ("free variable") evaluation:   y = 3 and (y + x) -> (3 + x)
- Execute simple math: 5 * 3 -> 15
- Boolean algebra reductions:
- gather            (x or y) and (x or z) -> x or (y and z)
- identity          false or y -> y
- annihilate        true or x -> true
- absorb            x and (x or y) -> x
- idempotence       y or y -> y
- complement        x and not(x) -> false
- doubleNegation    not(not(y)) -> y
- deMorgan          not(x) and not(y) -> not(x or y)
 
- gather            
Background
This is a side-track from SQLProvider, excellent tool that is kind of OR-mapper with auto-generated objects, so it compiles any databases to .NET-language, and works fast on design time in Visual Studio or other editors.
But I needed better SQL-queries. So this optimises .NET LINQ-expressions. These expressions were not meant to be compiled, so Nessos LinqOptimizer was not the right tool. I thought that .NET would optimize these automatically, but no.
Read the Getting started tutorial to learn more.
Documentation: http://thorium.github.io/Linq.Expression.Optimizer
Maintainer(s)
If you want more optimizations, please feel free to send PRs!
| Product | Versions 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 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. | 
| .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 is compatible. | 
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 is compatible. | 
| 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. | 
- 
                                                    .NETFramework 4.8.1- FSharp.Core (>= 8.0.301)
 
- 
                                                    .NETStandard 2.0- FSharp.Core (>= 8.0.301)
 
- 
                                                    .NETStandard 2.1- FSharp.Core (>= 8.0.301)
 
- 
                                                    net8.0- FSharp.Core (>= 8.0.301)
 
NuGet packages (4)
Showing the top 4 NuGet packages that depend on Linq.Expression.Optimizer:
| Package | Downloads | 
|---|---|
| SpeedyCourse.Entities Package Description | |
| Dosaic.Plugins.Persistence.EfCore.NpgSql A plugin-first dotnet framework for rapidly building anything hosted in the web. | |
| Dosaic.Plugins.Persistence.EfCore.Abstractions A plugin-first dotnet framework for rapidly building anything hosted in the web. | |
| XSpecification.Linq XSpecification is an implementation of Specification pattern for Linq and Elasticsearch | 
GitHub repositories (3)
Showing the top 3 popular GitHub repositories that depend on Linq.Expression.Optimizer:
| Repository | Stars | 
|---|---|
| rnwood/smtp4dev 
                                                            smtp4dev - the fake smtp email server for development and testing
                                                         | |
| scottksmith95/LINQKit 
                                                            LINQKit is a free set of extensions for LINQ to SQL and Entity Framework power users.
                                                         | |
| zzzprojects/System.Linq.Dynamic.Core 
                                                            The .NET Standard / .NET Core version from the System Linq Dynamic functionality.
                                                         | 
| Version | Downloads | Last Updated | 
|---|---|---|
| 1.0.33 | 777 | 9/8/2025 | 
| 1.0.32 | 1,602 | 6/19/2025 | 
| 1.0.31 | 658 | 6/4/2025 | 
| 1.0.29 | 9,617 | 3/31/2025 | 
| 1.0.28 | 1,648 | 3/26/2025 | 
| 1.0.27 | 806 | 3/18/2025 | 
| 1.0.24 | 7,181 | 11/7/2024 | 
| 1.0.23 | 35,805 | 6/26/2024 | 
| 1.0.22 | 560 | 6/26/2024 | 
| 1.0.21 | 9,275 | 4/5/2024 | 
| 1.0.20 | 621 | 4/2/2024 | 
| 1.0.18 | 8,343 | 3/11/2024 | 
| 1.0.16 | 49,111 | 10/8/2023 | 
| 1.0.15 | 22,638 | 3/7/2023 | 
| 1.0.13 | 187,531 | 5/27/2019 | 
| 1.0.12 | 39,438 | 8/31/2018 | 
| 1.0.11 | 33,016 | 1/1/2018 | 
| 1.0.10 | 2,230 | 1/1/2018 | 
| 1.0.9 | 27,971 | 6/5/2017 | 
| 1.0.8 | 2,303 | 5/10/2017 | 
| 1.0.7 | 29,766 | 10/7/2016 | 
| 1.0.6 | 2,124 | 10/6/2016 | 
| 1.0.5 | 2,070 | 10/5/2016 | 
| 1.0.4 | 2,281 | 10/3/2016 | 
| 1.0.3 | 2,315 | 8/30/2016 | 
| 1.0.2 | 2,140 | 8/30/2016 | 
| 1.0.1 | 2,048 | 8/30/2016 | 
| 1.0.0 | 2,176 | 8/27/2016 | 
A few new aritmethics rules
Minor performance improvements