title: Fluent NHibernate: cannot cast PersistentGenericBag to type 'System.Collections.Generic.ISet`
body: <p>I have an object Topic which is a self-related hierarchy where the child Topics are defined as </p>
  
  <pre><code>public class Topic : Entity {
     public ISet&lt;Topic&gt; ChildTopics { get; internal set; }
     public Topic ParentTopic { get; set; }
     ...
  }
  </code></pre>
  
  <p>I'm writing a form (MVC3) to produce a drop-down list (Html.DropDownListFor) of the first-level topics (theoretically this will eventually AJAX into a second drop-down for second-level topics), but when it goes to save, it produces the ever-popular "Cannot cast..." exception (see question title).</p>
  
  <p>The usual cause of this is that you used List or Set instead of IList or ISet, but I am using ISet, and it specifically says it can't cast to ISet.</p>
  
  <p>The reason this is a set is because you wouldn't want a Topic being a child of another Topic more than once. The table mapping create by Fluent NH <strong>automapping</strong> is correct with this override:</p>
  
  <p><code>mapping.HasMany&lt;Topic&gt;(t =&gt; t.ChildTopics).AsSet().Inverse().KeyColumn("TopicId");</code></p>