title: Mapping by code Zero-Or-One relationship
body: <p>I have the following database structure, which <strong>I cannot change</strong>:</p>
  
  <pre><code>CREATE TABLE Users (
      ID INT NOT NULL IDENTITY(1,1),
      PRIMARY KEY(ID)
  )
  
  CREATE TABLE UserAvatars (
      UserID INT NOT NULL,
      Width INT NOT NULL,
      Height INT NOT NULL,
  
      PRIMARY KEY(UserID),
      FOREIGN KEY(UserID) REFERENCES Users(ID),
  )
  </code></pre>
  
  <p>Basically, a User can have <strong>Zero-or-one</strong> avatars (I removed columns to simplify the example).</p>
  
  <pre><code>class User
  {
      public int ID { get; protected set; }
  
      public UserAvatar Avatar { get; set; }
  }
  
  class UserAvatar
  {
      public User User { get; set; }
      public int Width { get; set; }
      public int Height { get; set; }
  }
  </code></pre>
  
  <p>I am using the following mapping:</p>
  
  <pre><code>class UserMapping : ClassMapping&lt;User&gt;
  {
      public UserMapping() 
      {
          Id(x =&gt; x.ID, m =&gt; {
              m.Generator(Generators.Identity);
          });
  
          OneToOne(x =&gt; x.Avatar);
      }
  }
  
  class UserAvatarMapping : ClassMapping&lt;UserAvatar&gt;
  {
      public UserAvatar() 
      {
          Id(x =&gt; x.User, m =&gt;
          {
              m.Generator(Generators.Foreign&lt;User&gt;(u =&gt; u.ID));
          });
  
          Property(x =&gt; x.Width);
          Property(x =&gt; x.Height);
      }
  }
  </code></pre>
  
  <p>However, when trying run my app, I get an <code>NHibernate.MappingException</code>:</p>
  
  <blockquote>
    <p>NHibernate.MappingException : Could not compile the mapping document:
    mapping_by_code----> NHibernate.MappingException : Could not determine
    type for: MyApp.Models.UserAvatar, MyApp, for columns:
    NHibernate.Mapping.Column(User)</p>
  </blockquote>
  
  <p>I can't make any sense of this cryptic error.</p>
  
  <p>How do I accomplish the mapping where a <code>User</code> could have zero or one Avatars?</p>