Linq ThenFetch fails on deep where clause.
Description
Using a deep recursion in a where statement
.Where(p => p.Address.City.Name == "Test")
will cause a ThenFetch statement to fail with the following exception.
"Query specified join fetching, but the owner of the fetched association was not present in the select list "
var query = session.Query<Person>()
.Where(p => p.Address.City.Name == "Test")
.Fetch(r => r.Address)
.ThenFetch(a => a.City);
Removing the where statement or shortening it will cause the query to pass.
Environment
Activity
Sorry, probably it was fixed in 3.3.0, please check. Also there is issue related to this
Fix commited to master 6195424ffa3f1cb884a6983e847e26dcb45f4859
The same issue seems to apply when using OrderBy in conjunction with Fetch()/ThenFetch().
Unfortunately, I have no control in my code in which order these methods are called on the Queryable. This turns out to be a major issue for me.
Swapping the Fetch to the top does not always work. I have some very long Where clauses that are still getting this same problem even with the Fetch.ThenFetch being above everything else.
That's very interesting. Thanks for the tip!