title: QueryOver - How to select only one object from a join of three tables
body: <p>Assuming that I have objects similar to this: </p>
  
  <pre><code>public class User
  {
      public int UserId { get; set; } 
      public IList&lt;UsersRentingLog&gt; UsersRentLog { get; set; }
  }
  
  public class Car 
  {
      public int CarId { get; set; } 
      public IList&lt;UsersRentingLog&gt; CarRentLog { get; set; }
  }
  
  public class UsersRentingLog
  {
      public Userid { get; set; }
      public CarId { get; set; }
  }
  </code></pre>
  
  <p>Now, I want to select all users who rented a particular car.. </p>
  
  <p>The sql for this would simply be</p>
  
  <pre><code>select c.*
  from [User] u
      inner join UsersRentingLog l on u.userid = l.UserId
      inner join Car c on l.CarId = c.CarId
  where u.userid = @UserId
  </code></pre>
  
  <p>I am trying to get this query to work in QueryOver, NHibernate, and so far, I have got this:</p>
  
  <pre><code>DetachedCriteria dc = QueryOver.of&lt;User&gt;()
      .where(r =&gt; r.UserId == userId)
      .JoinQueryOver&lt;UsersRentingLog&gt;(l =&gt; l.UsersRentLog)
      .JoinQueryOver&lt;Car&gt;(c =&gt; c.Car)
      .DetachedCriteria
      ;
  </code></pre>
  
  <p>This is selecting, as expected, every single property from all three joined tables, but I actually want to select only Cars. 
  How can I do this please?</p>
  
  <p><hr>
  <strong>Update on correct answer</strong>  </p>
  
  <p>So, after the answer, I had to make few modifications (mostly minor syntax errors) and thought I'd post the working version.</p>
  
  <p>Because my user doesn't have a direct reference to the car, I had to modify the alias to go with this</p>
  
  <pre><code>UsersRentingLog logAlias = null; 
  var subQuery = QueryOver.of&lt;User&gt;()
      .Where(user =&gt; user.UserId == userId)
      .JoinAlias(user =&gt; user.UsersRentLog, () =&gt; logAlias)
      .subQuery.Select(Projections.Distinct(Projections.Property(() =&gt; logAlias.Car.Id)));
  
  
  var query = _session.QueryOver&lt;Car&gt;();
      query.WithSubquery.WhereProperty(car =&gt; car.Id).In(subQuery)
      .TransformUsing(Transformers.DistinctRootEntity)
      .List&lt;Car&gt;();
  </code></pre>
  
  <p>The above bit, I am using detached criteria, so I rewrote the second code block like so: </p>
  
  <pre><code>DetachedCriteria dc = QueryOver.Of&lt;Car&gt;()
      .WithSubquery.WhereProperty(car =&gt; car.Id).In(subQuery)
      .TransformUsing(new NHibernate.Transform.DistinctRootEntityResultTransformer())
      .DetachedCriteria
      ;
  </code></pre>