I’ve crafted two queries which both work fine, but I am really struggling to understand how to combine them. I think my biggest issue is the fact that I’ve used two different syntax for the queries, but I wasn’t sure how to express my first query without using the “SQL-esque” mark-up.
List<Task> tasksFromQueue = NHibernateSession.CreateQuery(
"Select t from Task t, QueueLocation q where q.Queue.ID = :queueID and (t.SiteID = q.ComponentID or t.OriginalSiteID = q.ComponentID)")
.SetParameter("queueID", queueID).List<Task>().ToList();
List<Task> tasksFromWorkflow = NHibernateSession
.CreateCriteria(typeof(Task), "Task")
.CreateCriteria("Task.Order", "Order")
.CreateAlias("Task.TaskDevice", "TaskDevice").List<Task>();
IEnumerable<Task> tasks = tasksFromWorkflow.Intersect(tasksFromQueue);
As you can see I have two issues:
- Using verbose syntax for the first query and the NHibernate mark-up for the second query.
- Hitting the DB twice and then intersecting the results.
The tasksFromWorkflow query is actually a lot more complicated than seen above. If you’d like to see the whole query click here. I wasn’t sure if the extra code really changed anything about my problem — so I decided to keep the immediately displayed snippet as short as possible while still explaining the problem.
I read that NHibernate doesn’t support intersection, so perhaps it isn’t possible to achieve in one query without becoming extremely convoluted?
i dont know how performant this will be but the idea should be clear