title: Fluent NHibernate complex Composite Id's
body: <p>I've been trying to get the following to work for a few hours now. But I can't seem to find out what I'm doing wrong here.</p>
  
  <p>I'm using Fluent Nhibernate automapper (and some overrides) to get this structure to work.</p>
  
  <pre><code>public class Game:IKeyed&lt;Guid&gt;
  {
      public virtual Guid Id { get; set; }
      //properties
  }
  
  public class Team : IKeyed&lt;Guid&gt;
  {
      public virtual Guid Id { get; set; }
      //Other properties
  
      public virtual IList&lt;GameTeam&gt; GameTeams { get; set; }
  }
  
  public class GameTeam:IKeyed&lt;GameTeamId&gt;
  {
      public virtual GameTeamId Id { get; set; }
      public virtual int CurrentRound { get; set; }
      public virtual IList&lt;GameTeamRound&gt; Rounds { get; set; }
  }
  
  public class GameTeamId
  {
      public virtual Game Game { get; set; }
      public virtual Team Team { get; set; }
  
      //equals stuff
  }
  
  public class GameTeamRound : IKeyed&lt;GameTeamRoundId&gt;
  {
      public virtual GameTeamRoundId Id { get; set; }
      //Properties
  
      public virtual IList&lt;TeamRoundDecision&gt; Decisions { get; set; }
  }
  
  public class GameTeamRoundId
  {
      public virtual GameTeam GameTeam { get; set; }
      public virtual int RoundNumber { get; set; }
  }
  </code></pre>
  
  <p>The GameTeam relation is something I can manage. But the GameTeamRound link is going a bit to far for the moment. :)
  I even have a level deeper. But I don't want to make the question more complicated.</p>
  
  <p>I'm using NHibernate to generate my database for me. So I'm starting from my model.
  To make this work I'm using some mapping overrides to make sure that these composite keys are working.</p>
  
  <pre><code>public class GameTeamOverride : IAutoMappingOverride&lt;GameTeam&gt;
  {
      public void Override(AutoMapping&lt;GameTeam&gt; mapping)
      {
          //mapping.IgnoreProperty(gt =&gt; gt.Id);
          mapping.CompositeId(gt =&gt; gt.Id)
                 .KeyProperty(id =&gt; id.Game.Id, "GameId")
                 .KeyProperty(id =&gt; id.Team.Id, "TeamId");
      }
  }
  
  public class GameTeamRoundOverride : IAutoMappingOverride&lt;GameTeamRound&gt;
  {
      public void Override(AutoMapping&lt;GameTeamRound&gt; mapping)
      {
          //mapping.IgnoreProperty(gtr =&gt; gtr.Id);
          mapping.CompositeId(gtr =&gt; gtr.Id)
                 .KeyProperty(id =&gt; id.GameTeam.Id.Game.Id, "GameId")
                 .KeyProperty(id =&gt; id.GameTeam.Id.Team.Id, "TeamId")
                 .KeyProperty(id =&gt; id.RoundNumber, "RoundId");
      }
  }
  </code></pre>
  
  <p>I've tried al sort of things. If you could point me into the right direction, that would be great. :)</p>
  
  <p>Thanks
  Tim</p>