QueryInterceptor.EntityFrameworkCore
8.0.10
dotnet add package QueryInterceptor.EntityFrameworkCore --version 8.0.10
NuGet\Install-Package QueryInterceptor.EntityFrameworkCore -Version 8.0.10
<PackageReference Include="QueryInterceptor.EntityFrameworkCore" Version="8.0.10" />
<PackageVersion Include="QueryInterceptor.EntityFrameworkCore" Version="8.0.10" />
<PackageReference Include="QueryInterceptor.EntityFrameworkCore" />
paket add QueryInterceptor.EntityFrameworkCore --version 8.0.10
#r "nuget: QueryInterceptor.EntityFrameworkCore, 8.0.10"
#addin nuget:?package=QueryInterceptor.EntityFrameworkCore&version=8.0.10
#tool nuget:?package=QueryInterceptor.EntityFrameworkCore&version=8.0.10
QueryInterceptor.Core
The problem
Normally when you're trying to modify expression trees you need to write an expression visitor. When trying to plug your expression visitor into an IQuerable's expression tree, you need to write a linq provider (yikes).
Implementation based on http://stackoverflow.com/questions/1839901/how-to-wrap-entity-framework-to-intercept-the-linq-expression-just-before-executi
The solution
QueryInterceptor introduces one extension method on IQueryable<T>
(InterceptWith
) that lets you plug in arbitrary expression visitors.
namespace QueryInterceptor
{
public static class QueryableExtensions
{
public static IQueryable<T> InterceptWith<T>(this IQueryable<T> source, params ExpressionVisitor[] visitors);
}
}
Basic Example
The example below uses an expression visitor that changes == to != anywhere in the expression tree.
public class EqualsToNotEqualsVisitor : ExpressionVisitor
{
protected override Expression VisitBinary(BinaryExpression node)
{
if (node.NodeType == ExpressionType.Equal)
{
// Change == to !=
return Expression.NotEqual(node.Left, node.Right);
}
return base.VisitBinary(node);
}
}
class Program
{
static void Main(string[] args)
{
var query = from n in Enumerable.Range(0, 10).AsQueryable()
where n % 2 == 0
select n;
// Print even numbers
foreach (var item in query)
{
Console.WriteLine(item);
}
Console.WriteLine();
// Print odd numbers
var visitor = new EqualsToNotEqualsVisitor();
foreach (var item in query.InterceptWith(visitor))
{
Console.WriteLine(item);
}
}
}
Sponsors
Entity Framework Extensions and Dapper Plus are major sponsors and proud to contribute to the development of QueryInterceptor.Core.
Product | Versions 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 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. |
-
net8.0
- JetBrains.Annotations (>= 2022.3.1)
- Microsoft.EntityFrameworkCore (>= 8.0.17)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on QueryInterceptor.EntityFrameworkCore:
Package | Downloads |
---|---|
Generics.Specifications.EntityFramework
Entity Framework hook for Generics.Specifications. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
8.0.10 | 133 | 6/22/2025 |
8.0.9 | 3,854 | 11/23/2023 |
7.0.10 | 125 | 6/22/2025 |
7.0.9 | 431 | 11/23/2023 |
7.0.8 | 7,815 | 2/22/2023 |
6.0.10 | 127 | 6/22/2025 |
6.0.9 | 145 | 11/23/2023 |
6.0.8 | 303 | 2/22/2023 |
2.0.10 | 130 | 6/22/2025 |
2.0.9 | 148 | 11/23/2023 |
2.0.8 | 300 | 2/22/2023 |
1.0.10 | 125 | 6/22/2025 |
1.0.9 | 155 | 11/23/2023 |
1.0.8 | 297 | 2/22/2023 |
1.0.7 | 9,455 | 12/1/2018 |
1.0.1 | 1,580 | 11/5/2017 |
1.0.0 | 1,159 | 11/2/2017 |
See releasenotes