ExpressionQuery<T> Class

Represents a compiled query that can be applied to an IQueryable<T>.

public sealed class ExpressionQuery<T>

Type parameters

T
The type of object to query against.

Remarks

This query type is designed for use with Entity Framework Core or other LINQ providers that translate expressions to SQL or other query languages.

Example

var queryBuilder = new ExpressionQueryBuilder<Person>();
queryBuilder.AddHandler("name", item => item.FullName);
var query = queryBuilder.Build("name:John");

// Apply works on any IQueryable<T>, such as an Entity Framework Core DbSet<T>
var people = new[] { new Person("John Doe", 30), new Person("Jane Doe", 25) }.AsQueryable();
var results = query.Apply(people).ToList();
Assert.Equal("John Doe", Assert.Single(results).FullName);

Properties

NameDescription
PredicateGets the compiled predicate expression, or null if the query matches all items.
TextGets the original query text.

Gets the compiled predicate expression, or null if the query matches all items.

public Expression<Func<T, bool>>? Predicate { get; }

Gets the original query text.

public string Text { get; }

Property value

string

Methods

NameDescription
Apply(IQueryable<T>)Applies the query to an IQueryable<T>.

Apply(IQueryable<T>)

ExpressionQuery`1.cs

Applies the query to an IQueryable<T>.

public IQueryable<T> Apply(IQueryable<T> queryable)

Parameters

queryable IQueryable<T>
The queryable to filter.

Returns

IQueryable<T> A filtered queryable.