We're updating the issue view to help you get more done. 

Select Expressions Cache Entities

Description

We have a few queries where we are pulling predicate expressions into the select clause so that we can batch a complex set of queries.

Our problem is that when entity comparison is part of the predicate the expression is not sent to the database but rather broken and the comparison is run in memory. The query plan (including the ProjectionExpression) is then cached. Subsequent executions try to compare the newly returned entity with the cached entity, which will fail if the entity was from a different session.

Trivial, but clear example

1 2 3 4 5 6 7 8 9 10 using (var session = OpenSession()) { var bob = session.Query<Owner>.Single(o => o.Name == "Bob"); var query = session.Query<Entity>.Select(e => new { Id = e.Id, OwnedByBob = e.Owner == bob, }); var results = query.ToList(); }

The first time the query executes (within an ISessionFactory instance) the values of OwnedByBob correctly reflect the ownership. Subsequent executions will have all OwnedByBob values false.

Environment

None

Status

Assignee

Unassigned

Reporter

Duncan Munro

Components

Fix versions

Affects versions

4.0.4

Priority

Major