title: NHibernate: using an existing public int field as record Id
body: <p>I have an existing class that I'd like to persist as-is.</p>
  
  <pre><code>class Foo
  {
      public int Id;
      ...
  }
  </code></pre>
  
  <p>I have the following ClassMap:</p>
  
  <pre><code>class FooMap : ClassMap&lt;Foo&gt;
  {
      Id(x =&gt; x.Id);
      ...
  }
  </code></pre>
  
  <p>Building a session factory results in an invalid cast exception. My setup works if my entity class has the standard "public virtual int Id { get; private set; }" property. I'm interested in learning if I can use the field "public int Id" as the nhibernate Id.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>It looks like you can't currently do this with FluentNHibernate, because it always excepts to deal with properties. This can be accomplished by mixing in an NHibernate xml mapping. <a href="http://groups.google.com/group/fluent-nhibernate/browse_thread/thread/97ac8735706e248f/7d276a8cef311a9d?lnk=gst" rel="nofollow noreferrer">Details on the mailing list</a>.</p>