Fixed
Details
Details
Assignee
Alex Zaytsev
Alex ZaytsevReporter
o
oLabels
Components
Fix versions
Affects versions
Priority
Who's Looking?
Open Who's Looking?
Created October 18, 2011 at 8:32 PM
Updated September 21, 2014 at 12:40 PM
Resolved June 4, 2012 at 8:00 PM
When using Query<T>, Where clause followed by Fetch and then by OrderBy produces incorrect results by failing to include where predicate into the SQL at all.
Problem does not appear if removing Fetch or OrderBy from the sequence.
Erroneous behavior can be fixed by moving Where after Fetch, but please note that this workaround is not always possible; for example, if query including filtering is created at upper level of a call tree and then being processed by adding fetch/order in methods knowing nothing about where given IQueryable came from. Even throwing would be better than silently returning incorrect data, as it prompts to check each and every query, and correct one can be easily made incorrect by adding fetching or ordering.
For example, query like this
var contacts = session.Query<Contact>()
.Where(c => c.Id != contact.Id)
.Fetch(c => c.Profile)
.OrderBy(c => c.Id)
.ToList();
produces the following SQL without any trace of filtering by contact id:
select
contact0_.Id as Id0_0_,
profile1_.Id as Id1_1_,
contact0_.Profile as Profile0_0_
from
Contact contact0_
left outer join
Profile profile1_
on contact0_.Profile=profile1_.Id
order by
contact0_.Id asc
I will attach a failing test case to this issue.