title: NH 3.3 Composite-ID mapping by code
body: <p><img src="https://i.stack.imgur.com/jO0fe.png" alt="Diagram"></p>
  
  <p>I am pulling my hair out here trying to figure out how to map the UsersRoles table listed below. I don't look good bald so please help :)</p>
  
  <p>//Here is the Entity</p>
  
  <pre><code>public class UsersRole
  {
      public UsersRole() { }
      public virtual User User { get; set; }
      public virtual Role Role { get; set; }
      public virtual System.Guid UserId { get; set; }
      public virtual System.Guid RoleId { get; set; }
  
  
  }
  </code></pre>
  
  <p>//Here is the mapping so far</p>
  
  <pre><code>public class UsersRoleMap : ClassMapping&lt;UsersRole&gt;
  {
      public UsersRoleMap()
      {
          Table("UsersRoles");
          Lazy(true);
  
         // ComponentAsId(); How does this work??
  
  
          Property(x =&gt; x.UserId, map =&gt; map.Column(c =&gt;
              {
                  c.Name("UserId");
                  c.NotNullable(true);
                  c.Length(30);
                  c.SqlType("uniqueidentifier");
              }));
          Property(x =&gt; x.RoleId, map =&gt; map.Column(c =&gt;
              {
                  c.Name("RoleId");
                  c.NotNullable(true);
                  c.Length(30);
                  c.SqlType("uniqueidentifier");
              }));
      }
  }
  </code></pre>
  
  <p>Please see the comment in the mapping for ComponentAsId</p>
  
  <p>Thanks in advance if someone can get me on the right track</p>