title: How to map part of aspnet_Users table using Fluent NHibernate
body: <p>I'm trying to get Fluent NHibernate 1.0 RTM to map a User entity for me so that I have access to UserId and UserName inside my ASP.NET MVC application via NHibernate.</p>
  
  <p>I have:</p>
  
  <pre><code>public class User
  {
      public virtual Guid UserId { get; protected set; }
      public virtual string UserName { get; protected set; }
  }
  </code></pre>
  
  <p>It represents the aspnet_Users table with only the relevant columns to be mapped. This is the only entity that is not being automapped. Here is my mapping:</p>
  
  <pre><code>public class UserMap : ClassMap&lt;User&gt;
  {
      public UserMap()
      {
          Id(x =&gt; x.UserId);
          Map(x =&gt; x.UserName);
          WithTable("aspnet_Users");
      }
  }
  </code></pre>
  
  <p>Everything else is getting automapped with conventions.</p>
  
  <p>Here are my PrimaryKeyConvention and TableNameConvention:</p>
  
  <pre><code>public class PrimaryKeyConvention : IIdConvention
  {
      public void Apply(IIdentityInstance instance)
      {
          instance.Column(instance.Property.ReflectedType.Name + "Id");
          instance.UnsavedValue(System.Guid.Empty.ToString());
          instance.GeneratedBy.GuidComb();
      }
  }
  
  public class TableNameConvention : IClassConvention
  {
      public void Apply(IClassInstance instance)
      {
          instance.Table(Inflector.Net.Inflector.Pluralize(instance.EntityType.Name));
      }
  }
  </code></pre>
  
  <p>The Mapping process fails right after executing the ClassMap code (which comes before all automapping), followed by the TableNameConvention code, followed by the PrimaryKeyConvention code. The failure is in PrimaryKeyConvention because instance.Property is null. I tried to do an if(instance.Property != null) but that
  terminates the mapping process early with a "the required attribute 'class' is missing" error. I also had an if (instance.EntityType != typeof(User)) in the TableNameConvention, but took out when it was making no difference.</p>
  
  <p>What is going on here? First of all, why is the AutoMapping processes calling the conventions for the ClassMap? Second, why is the PrimaryKenConvention getting passed an instance.Property == null? How can I get this to work so that the mapping process moves on and maps the rest of my entities using AutoMapping + conventions?</p>
  
  <p>Note, I had this all working for months under an earlier version of FNH prior to the refactor for 1.0 RTM.</p>