I’m writing a handler for a search form. The object being searched has 3 boolean flags and several collections (as ISet)
These are related in that the flags represent abstract groupings of individual members of the collections. In this specific case, the collections represent Counties, Cities, and very broad “Regions.” The boolean flags are for the author to specify that an entity IsOutOfState, IsStatewide, and/or IsEverywhere (e.g. Internet).
There are additional non-geographic collections (e.g. Topics). Any restriction on this would be “and”ed with the geographic restrictions.
On the search form, a user can check off particular geographic areas of interest (specific counties and/or cities and/or regions) as well as broadening their search to include items with one or more of the extra boolean flags set (if they don’t check the box, we don’t restrict the boolean fields).
Writing this manually in SQL, I’d do something like:
SELECT ... FROM foo LEFT JOIN FooCounties fc ON foo.ID = fc.ID
LEFT JOIN FooCities fct ON foo.ID = fct.ID ...
INNER JOIN FooTopics ft ON foo.ID = ft.ID
WHERE (fc.CountyID IN (1, 2, ...) OR fct.CityID IN (1, 3, 5, ...) OR foo.IsStatewide = 1)
AND ft.TopicID IN (1, 4, 7, ...)
How can I translate this to QueryOver? So far I’ve got the Topics and other AND criteria OK by something like this:
var query = Session.QueryOver<foo>();
if (SelectedTopicIDs.Count > 0) {
var TopicSubQ = QueryOver.Of<foo>().JoinQueryOver<Topic>(t => t.Topics)... etc.
query = query.WithSubquery.WhereProperty(p => p.Id).In(TopicSubQ);
}
But I can’t figure out how I would use Disjunction to compare up to 3 bools and up to 3 subqueries, and then merge that all as an ‘and’ with the existing criteria.
1 Answer