title: Linq to Nhibernate - call method inside Select breaks IQueryable
body: <p>I need <code>IQueryable</code> inside my business logic assembly based on Domain entities. I want to use auto-mapper for this purposes due to big amount of similar entities.  </p>
  
  <p>Works:</p>
  
  <pre><code>_repository.GetList&lt;AgentDto&gt;()
          .Select(dto =&gt; new Agent{Login = dto.Login, Password = dto.Password})
          .Where(...).ToList();
  </code></pre>
  
  <p>Does not work (I could not place <code>Where</code> (another assembly) before <code>Select</code>):</p>
  
  <pre><code>_repository.GetList&lt;AgentDto&gt;()
          .Select(dto =&gt; ToAgent(dto))
          .Where(...).ToList();
  
  private Agent ToAgent(AgentDto dto)
      {
          return new Agent{Login = dto.Login, Password = dto.Password};
      }
  </code></pre>
  
  <p>Exception: </p>
  
  <pre><code>System.NotSupportedException was caught
    Message=CustomerInfo.Domain.Support.Agent ToAgent(CustomerInfo.DAL.DTO.AgentDto)
    Source=NHibernate
    StackTrace:
         at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitMethodCallExpression(MethodCallExpression expression)
         at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitExpression(Expression expression)
         at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitMemberExpression(MemberExpression expression)
         at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitExpression(Expression expression)
         at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitBinaryExpression(BinaryExpression expression)
         at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitExpression(Expression expression)
         at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitBinaryExpression(BinaryExpression expression)
         at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitExpression(Expression expression)
         at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.Visit(Expression expression, VisitorParameters parameters)
         at NHibernate.Linq.Visitors.QueryModelVisitor.VisitWhereClause(WhereClause whereClause, QueryModel queryModel, Int32 index)
         at Remotion.Linq.Clauses.WhereClause.Accept(IQueryModelVisitor visitor, QueryModel queryModel, Int32 index)
         at Remotion.Linq.QueryModelVisitorBase.VisitBodyClauses(ObservableCollection`1 bodyClauses, QueryModel queryModel)
         at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel)
         at NHibernate.Linq.Visitors.QueryModelVisitor.Visit()
         at NHibernate.Linq.Visitors.QueryModelVisitor.GenerateHqlQuery(QueryModel queryModel, VisitorParameters parameters, Boolean root)
         at NHibernate.Linq.NhLinqExpression.Translate(ISessionFactoryImplementor sessionFactory)
         at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(String queryIdentifier, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory)
         at NHibernate.Engine.Query.HQLExpressionQueryPlan.CreateTranslators(String expressionStr, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory)
         at NHibernate.Engine.Query.HQLExpressionQueryPlan..ctor(String expressionStr, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory)
         at NHibernate.Engine.Query.HQLExpressionQueryPlan..ctor(String expressionStr, IQueryExpression queryExpression, Boolean shallow, IDictionary`2 enabledFilters, 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 System.Linq.Queryable.Count[TSource](IQueryable`1 source, Expression`1 predicate)
         at CustomerInfo.BLL.Authentication.AgentManagementService.ValidateAgent(String agentLogin, String password) in D:\Projects\CustomerInfo\CustomerInfo.BLL\Authentication\AgentManagementService.cs:line 49
    InnerException: 
  </code></pre>