Class ScalarValueQueryInterceptor
- Namespace
- Trellis.EntityFrameworkCore
- Assembly
- Trellis.EntityFrameworkCore.dll
An EF Core query expression interceptor that enables natural scalar value object
syntax in LINQ queries — comparisons, string methods, and properties translate to SQL
without requiring .Value.
public sealed class ScalarValueQueryInterceptor : IQueryExpressionInterceptor, ISingletonInterceptor, IInterceptor
- Inheritance
-
ScalarValueQueryInterceptor
- Implements
- Inherited Members
- Extension Methods
Examples
With this interceptor registered, these LINQ expressions work directly:
// Natural value object syntax — no .Value needed
context.Customers.Where(c => c.Name == "Alice");
context.Customers.Where(c => c.Name.StartsWith("Al"));
context.Customers.Where(c => c.Name.Length > 3);
context.Customers.OrderBy(c => c.Name);
// Specifications with domain types
public override Expression<Func<TodoItem, bool>> ToExpression() =>
todo => todo.Status == TodoStatus.Active && todo.DueDate < _asOf;
Remarks
Register via optionsBuilder.AddTrellisInterceptors() — this registers both
the MaybeQueryInterceptor and this interceptor.
Methods
QueryCompilationStarting(Expression, QueryExpressionEventData)
Rewrites the query expression tree before compilation, converting scalar value object expressions to forms that EF Core can translate to SQL.
public Expression QueryCompilationStarting(Expression queryExpression, QueryExpressionEventData eventData)
Parameters
queryExpressionExpressioneventDataQueryExpressionEventData