很多人在最初使用NHibernate来操作一对多关系时,使用了 <set>标签,如:
<set name="Students">
  <key column="CId"/>
  <one-to-many class="NHStusManagerApp.Student"/>
</set>
对应类中使用:
public class Classes{
  private ISet<Student> _students;
  public virtual ISet<Student> Students
  {
     get { return _students; }
     set { _students = value; }
  }
}
看上去很普通,但运行时会报错如下:

无法将类型为“NHibernate.Collection.Generic.PersistentGenericSet`1[NHStusManagerApp.Student]”的对象强制转换为类型“System.Collections.Generic.ISet`1[NHStusManagerApp.Student]”。

  报错的原因很显然,是类型错误,也就是说,配置文件里的set标签是告诉NHibernate在实体类中使用Set集合属性来装载关联数据(如:一班里的50个学生),此时就会使用班级类里的Students属性来存储学员,但此时应该使用:
  Iesi.Collections.Generic 下的 ISet,需要添加 Iesi.Collections.dll 程序集.
  但如果没有添加的话,则是使用 System.Collections.Generic下的 ISet.
  所以出现这个无法转换的错误.

from:http://www.oumind.com/html/tech/NHibernateUnableCastPersistentGenericSet_20120429.html