In NHibernate, how do I combine two DetachedCriteria instances
Posted
by Trevor
on Stack Overflow
See other posts from Stack Overflow
or by Trevor
Published on 2010-04-12T13:46:49Z
Indexed on
2010/04/12
14:03 UTC
Read the original article
Hit count: 667
nhibernate
|detachedcriteria
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?
© Stack Overflow or respective owner