In NHibernate, how do I combine two DetachedCriteria instances
- by Trevor
My scenario is this: I have a base NHibernate query to run of the form (I've coded it using DetachedCriteria , but describe it here using SQL syntax):
SELECT * FROM Items I INNER JOIN SubItems S on S.FK = I.Key
The user interface to show the results of this join allows the user to specify additional criteria: Say:
I.SomeField = 'UserValue'.
Now, I need the final load command to be:
SELECT * FROM Items I INNER JOIN SubItems S on S.FK = I.Key
WHERE I.SomeField = 'UserValue'
My problem is: I've created a DetachedCriteria with the 'static' aspect of the query (the top join) and the UI creates a DetachedCriteria with the 'dynamic' component of the query. I need to combine the two into a final query that I can execute on the NHibernate session.
DefaultCriteria.Add() takes an ICriterion (which are created using the Expression class, and maybe other classes I don't know of which could be the solution to my problem).
Does anyone know how I might do what I want?