0

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?

Afshar Mohebi
  • 10,479
  • 17
  • 82
  • 126

4 Answers4

3

linq-to-nh DOES support sub queries in where clause. It is exact thing I needed. I was wrong with my previous answer. Both martijnboland and Stefan Steinegger were right. To see how you do sub-queries in linq-to-nh see this and this. There is also limitations.

Community
  • 1
  • 1
Afshar Mohebi
  • 10,479
  • 17
  • 82
  • 126
1

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

Stefan Steinegger
  • 63,782
  • 15
  • 129
  • 193
  • Unfortunately Criteria does not support subqueries too. Indeed LINQ-to-NHibernate is based on ICriteria and this disability origins from ICriteria itself. – Afshar Mohebi Mar 02 '10 at 09:39
  • 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 Mar 03 '10 at 16:16
  • after a long long time I'm convinced that you were right. Sorry! – Afshar Mohebi Nov 15 '10 at 18:27
0

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

Drevak
  • 867
  • 3
  • 12
  • 26
0

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.

Afshar Mohebi
  • 10,479
  • 17
  • 82
  • 126