Class MaybeQueryInterceptor
- Namespace
- Trellis.EntityFrameworkCore
- Assembly
- Trellis.EntityFrameworkCore.dll
An EF Core query expression interceptor that automatically rewrites Maybe<T> property accesses in LINQ expression trees to their underlying storage member equivalents.
public sealed class MaybeQueryInterceptor : IQueryExpressionInterceptor, ISingletonInterceptor, IInterceptor
- Inheritance
-
MaybeQueryInterceptor
- Implements
- Inherited Members
- Extension Methods
Examples
With this interceptor registered, these LINQ expressions work directly:
// Natural LINQ — no explicit extension methods needed
context.Customers.Where(c => c.Phone.HasValue)
context.Orders.Where(o => o.SubmittedAt.GetValueOrDefault(DateTime.MaxValue) < cutoff)
// Specifications with Maybe<T> properties
public override Expression<Func<Order, bool>> ToExpression() =>
order => order.Status == OrderStatus.Submitted
&& order.SubmittedAt.GetValueOrDefault(DateTime.MaxValue) < _cutoff;
Remarks
When registered, this interceptor allows natural LINQ syntax with Maybe<T>
properties in queries and specifications, without requiring explicit extension methods
like WhereHasValue or WhereLessThan.
Register by calling optionsBuilder.AddInterceptors(new MaybeQueryInterceptor()).
Methods
QueryCompilationStarting(Expression, QueryExpressionEventData)
Rewrites the query expression tree before compilation, replacing Maybe<T> property accesses with EF Core-translatable storage member references.
public Expression QueryCompilationStarting(Expression queryExpression, QueryExpressionEventData eventData)
Parameters
queryExpressionExpressioneventDataQueryExpressionEventData