Possible premature query materialization


Marten1004 Warning

Cause

A query (IQuerySession.Query, IQuerySession.QueryAsync, IBatchedQuery.Query) is materialized without any predicates.

Reason for rule

Materializing the query before applying any predicates leads further evaluation of any predicates to be executed in memory of the querying process.

How to fix violations

Apply predicates before materializing the query.

Examples

Violates

// Fetch all issues & evaluate predicate in memory
var issues = session.Query<Issue>().ToList().Where(x => x.Critical);

Does not violate

// Evaluate predicate in database, then materialize matches
var issues = session.Query<Issue>().Where(x => x.Critical).ToList();