title: Persisting simple tree with (Fluent-)NHibernate leads to System.InvalidCastException
body: <p>there seems to be a problem with recursive data structures and (Fluent-)NHibernate or its just me, being a complete moron...</p>
  
  <p>here's the tree:</p>
  
  <p>public class SimpleNode {</p>
  
  <pre><code>public SimpleNode ()
  {
      this.Children = new List&lt;SimpleNode&gt; ();
  }
  
  public virtual SimpleNode Parent { get; private set; }
  public virtual List&lt;SimpleNode&gt; Children { get; private set; }
  
  public virtual void setParent (SimpleNode parent)
  {
      parent.AddChild (this);
      Parent = parent;
  }
  
  public virtual void AddChild (SimpleNode child)
  {
      this.Children.Add (child);
  }
  
  public virtual void AddChildren (IEnumerable&lt;SimpleNode&gt; children)
  {
      foreach (var child in children) {
          AddChild (child);
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>the mapping:</p>
  
  <p>public class SimpleNodeEntity : ClassMap&lt;SimpleNode&gt;</p>
  
  <p>{ </p>
  
  <pre><code>public SimpleNodeEntity ()
  {
      Id (x =&gt; x.Id);
  
      References (x =&gt; x.Parent).Nullable ();
  
      HasMany (x =&gt; x.Children).Not.LazyLoad ().Inverse ().Cascade.All ().KeyNullable ();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>now, whenever I try to save a node, I get this:</p>
  
  <p>System.InvalidCastException: Cannot cast from source type to destination type. at (wrapper dynamic-method) SimpleNode. (object,object[],NHibernate.Bytecode.Lightweight.SetterCallback) at NHibernate.Bytecode.Lightweight.AccessOptimizer.SetPropertyValues (object,object[]) at NHibernate.Tuple.Entity.PocoEntityTuplizer.SetPropertyValuesWithOptimizer (object,object[])</p>
  
  <p>My setup:</p>
  
  <p>Mono 2.8.1 (on OSX), NHibernate 2.1.2, FluentNHibernate 1.1.0</p>