'Merge two QueryOvers
If I have two separate QueryOvers; for instance:
var q1 = QueryOver.Of<Customer>(() => customerAlias)
.select(x => x.RegionId);
var q2 = QueryOver.Of<Store>(() => storeAlias)
.select(x => x.RegionId);
And I wanted to check, via a subquery, whether or not an item appears in either of these records, I had thought I could try something like:
query = query
.Where(
Restrictions.Disjunction()
.Add(Subqueries.WhereProperty<Region>(x => x.Id).In(q1))
.Add(Subqueries.WhereProperty<Region>(x => x.Id).In(q2))
);
But when this section of code runs, the query doesn't seem to return the same type of results; where the code later tries to extract the ids, I get the error:
NHibernate.QueryException: 'could not resolve property: Id of: Models.Region'
From the code:
var allRegionIds = query.Select(x => x.Id).List<long>().ToList();
If I change the code back to what I had (below), which only checks in one subquery, then I don't get this error.
query = query
.WithSubquery
.WhereExists(q1);
Any thoughts on either:
- How could I merge two QueryOvers together so I can use my working code that only checks against 1 QueryOver
- Why am I getting the error further down in the code when I use the code which checks against 2 QueryOvers?
Any help would be greatly appreciated
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
