title: NHibernate LINQ queries with nested .Any() conditions
body: <p>Here are what my classes look like:</p>
  
  <pre><code>class User
  {
      IList&lt;UserRedemptionCode&gt; UserRedemptions;
  }
  
  class UserRedemptionCode
  {
      string Code;
  }
  
  class Course
  {
      IList&lt;CourseRedemptionCode&gt; CourseRedemptions;
  }
  
  class CourseRedemptionCode
  {
      string Code;
      string SomeData;
  }
  </code></pre>
  
  <p>I want to retrieve all of the courses that match a redemption code that is associated with a user. Here is the current IQuerable call I am making:</p>
  
  <pre><code>IQueryable&lt;Course&gt; query = Courses.Where(
      course =&gt; course.CourseRedemptions.Any(
          cr =&gt; user.UserRedemptions.Any(rc =&gt; cr.Code == rc.Code));
  </code></pre>
  
  <p>However, this doesn't seem to work with NHibernate. I get this exception:</p>
  
  <pre><code>System.NotSupportedExceptionSpecified method is not supported.
    at NHibernate.Hql.Ast.ANTLR.PolymorphicQuerySourceDetector.GetClassName(IASTNode querySource)
    at NHibernate.Hql.Ast.ANTLR.PolymorphicQuerySourceDetector.Process(IASTNode tree)
    at NHibernate.Hql.Ast.ANTLR.AstPolymorphicProcessor.Process()
    at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(IASTNode ast, String queryIdentifier, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory)
    at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(String queryIdentifier, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory)
    at NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow, IDictionary`2 enabledFilters)
    at NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow)
    at NHibernate.Impl.AbstractSessionImpl.CreateQuery(IQueryExpression queryExpression)
    at NHibernate.Linq.DefaultQueryProvider.PrepareQuery(Expression expression, IQuery&amp; query, NhLinqExpression&amp; nhQuery)
    at NHibernate.Linq.DefaultQueryProvider.Execute(Expression expression)
    at NHibernate.Linq.DefaultQueryProvider.Execute[TResult](Expression expression)
    at Remotion.Linq.QueryableBase`1.GetEnumerator()
    at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
    at System.Web.Http.Filters.EnumerableEvaluatorFilter.Convert[T](Object input)
    at System.Web.Http.Filters.EnumerableEvaluatorFilter.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
    at System.Web.Http.Filters.ActionFilterAttribute.CallOnActionExecuted(HttpActionContext actionContext, HttpResponseMessage response, Exception exception)
    at System.Web.Http.Filters.ActionFilterAttribute.&lt;&gt;c__DisplayClass4.&lt;System.Web.Http.Filters.IActionFilter.ExecuteActionFilterAsync&gt;b__2(HttpResponseMessage response)
    at System.Threading.Tasks.TaskHelpersExtensions.&lt;&gt;c__DisplayClass2e`2.&lt;Then&gt;b__2d(Task`1 t)
    at System.Threading.Tasks.TaskHelpersExtensions.ThenImpl[TTask,TOuterResult](TTask task, Func`2 continuation, CancellationToken cancellationToken)
  </code></pre>
  
  <p>There is also another issue, in this query I get back a list of courses, but I also need the CourseRedemptionCode associated with the user so I can get SomeData.</p>
  
  <p>Any ideas? Is there another way to do this query?</p>