views:

258

answers:

3

I know LINQ-to-NHibernate currently does not support sub-queries (http://ayende.com/Blog/archive/2009/07/26/nhibernate-linq-1.0-released.aspx).

Is there any workaround about it?

A: 

I have not worked with nhibernate to linq but i'm sure that you can translate almost any subquery to a join

Drevak
Unfortunately it does not support joins too!
afsharm
Note that there is a difference between subqueries in the select and subqueries in the where clause: subqueries in the where clause are supported and work fine (Any(), Count() etc.)
martijnboland
Dear martijn, I'm going to use "select subqueries"
afsharm
+1  A: 

I think the workaround is simply to use HQL or Criteria.

Stefan Steinegger
Unfortunately Criteria does not support subqueries too. Indeed LINQ-to-NHibernate is based on ICriteria and this disability origins from ICriteria itself.
afsharm
Criteria **DOES** support subqueries. It's built with `DetachedCriteria` and added with `.Add(Subqueries.Blah(subquery))` (where `Blah` is `Exists` or `PropertyIn` or something like this)
Stefan Steinegger
A: 

I have used a two part LINQ query as a work around. A LINQ-to-NHibernate for not related sub query section and a LINQ-to-Object for sub query related section of the query. Please see http://afsharm.blogspot.com/2010/03/dealing-with-subqueries-in-linq-to.html for more detail.

afsharm