Quote:
Can you do an arbitrary join or does NHibernate limit the joins to associated collections?
Yes. You are not limited to the join specified in your mapping.
However, you will have to use the theta-join style (i.e., comparing ids in the WHERE clause), like it is done in the example subquery. You cannot use the "join" word in such queries.
Quote:
Is there a way to pluck out the sql being generated by NHibernate programmatically at runtime? I have something in mind and it'd be helpful to be able to grab the generated SQL without it actually querying the DB.
No, there isn't.
You can easily log the generated SQL to a special file, for example (which I explain in detail here
http://hibernar.org/articulos_en/logging.php ), but that is only SQL that has been actually executed against the DB.
Quote:
Do you know of an article with a more in-depth look at ICriteria/HQL than the standard NHibernate manual?
Not that I know. And I agree with you that the projections/transformations part is very poorly documented. But there is not that much to it, either. Just keep experimenting stuff until you get the result you want.
For example, at this point I am sure you know more about projections than I do. Nevertheless, playing a little with the example you gave me, I could create the Criteria query you need:
(forgive me the Java notation, I am not much into Microsoft)
Code:
DetachedCriteria dc = DetachedCriteria.forClass( Task.class)
.setProjection(Projections.projectionList()
.add(Projections.max("id"))
.add(Projections.groupProperty("procedureId"),""))
.add(
Expression.and(
Expression.eq("scheduledBy",1),
Expression.in("procedureId",new Integer[]{1,2})));
Criteria criteria = s1.createCriteria(Task.class).add( Subqueries.eq("id",dc) );
List<Task> result=criteria.list();
notice that my only change was that "in(...)", it's very intuitive.