Hi,
This one has been making my head hurt (which is easy since I'm a NHibernate newbie): how can I represent the following query (T-SQL) through the Criteria API?
DECLARE @pcode VARCHAR(8)
SET @pcode = 'somecode'
SELECT d.*
FROM document d
WHERE EXISTS (
SELECT 1
FROM project p
WHERE p.id = d.projectId AND p.code = @pcode)
OR EXISTS (
SELECT 1
FROM job j INNER JOIN project p ON p.id = j.projectId
WHERE j.id = d.jobId AND p.code = @pcode)
(A Document has two possible associations, Project or Job. Only one of them has a value at a given time; the other has null
.)
The goal is to load all Documents that are directly associated with a given Project or indirectly through a Job.
Thanks.