title: nhibernate queryover with complex join over non-related entities
body: <p>So I've spent the last few hours looking for an answer and I can't seem to find anything that makes sense.</p>
  
  <pre><code>public class Game
  {
     public virtual Guid ID { get; set; }
     public virtual ResultStructure Structure { get; set; }
     public virtual List&lt;Result&gt; Results { get; set; }
  }
  
  public class Result
  {
    public virtual Player Player { get; set; }
    public virtual int Position { get; set; }
  }
  
  public class ResultStructure
  {
    public virtual Guid ID { get; set; }
    public virtual List&lt;ResultOutcomes&gt; Outcomes { get; set;}
  }
  
  public class ResultOutcomes
  {
    public virtual int Position { get; set; }
    public virtual int Points { get; set; }
  }
  
  public class PlayerSummary
  {
    public virtual Player Player { get; set; }
    public virtual int Points { get; set; }
  }
  </code></pre>
  
  <p>What I'm trying to do is get a list of players and the points they've earned across a multitude of different games (there are multiple entities above <code>game</code> that contain lists of games). So the end result of the query would be <code>List&lt;PlayerSummary&gt;</code>  The SQL I'm looking for would look something like this:</p>
  
  <pre><code>SELECT p.*, Sum(rs.points) FROM result r
    JOIN player p on r.playerid = p.id
    JOIN game g on r.gameid = g.id
    JOIN resultstructure rs on g.resultstructureid = rs.id
    JOIN resultoutcomes ro on rs.id = ro.resultstructureid AND ro.position = r.position
  </code></pre>
  
  <p>Note, I will also need to do some querying/summing against the structure entity which is why it's included.</p>
  
  <p>I'm trying to do this with NHibernate, using the TypeSafe stuff, and my plan is for the application to be database agnostic, so I can't use direct SQL (currently it's using Postgres, but I may move to SQL server at some point).</p>
  
  <p>I don't particularly want to use the "HQL" stuff where you use those magic strings, so I'm trying to use Linq or QueryOver/Query.</p>
  
  <p>Can anyone point me in the right direction?</p>