title: NHibernate: use of IEnumerable as collection type results in error
body: <p>I have a class which uses an ISet as a collection type as below:</p>
  
  <pre><code>  public class Client
    {
      private ISet&lt;Contact&gt; _contacts = new HashedSet&lt;Contact&gt;();
      public virtual ISet&lt;Contact&gt; Contacts { get { return _contacts; } }
    }
  </code></pre>
  
  <p>I don't want the collection itself to be able to be modified externally. However, if I change the property's type to IEnumerable as below:</p>
  
  <pre><code>  public class Client
    {
      private ISet&lt;Contact&gt; _contacts = new HashedSet&lt;Contact&gt;();
      public virtual IEnumerable&lt;Contact&gt; Contacts { get { return _contacts; } }
    }
  </code></pre>
  
  <p>Then whenever I try to use this class I get the NHibernate error:</p>
  
  <p>System.InvalidCastException: Unable to cast object of type 'NHibernate.Collection.Generic.PersistentGenericBag<code>1[Kctc.BusinessLayer.ProbateAssist.Entities.Contact]' to type 'Iesi.Collections.Generic.ISet</code>1[Kctc.BusinessLayer.ProbateAssist.Entities.Contact]'.</p>
  
  <p>What gives? How can I make the public version of the collection read only?</p>
  
  <p>NB I've also tried to use ReadOnlyCollection, and get the same error.</p>