Nhibernate中的集合眏射

        在Nhibernate中经常遇到one-to-many和many-to-many的关系映射,用一些集合类来保存关联的many集合,这些集合类包括: IList、Array和IDictionary。其在map文件中对应的元素为 list(IList)、set(IDictionary)、bag(IList)、map(IDictionary)和array(Array)。
        其中比较特殊的是List和Array,它们需要在关联表中用一个单独字段来保存列表(List)或数组(Array)的索引(如childRecord[i]中的i),虽然list可以实现对无序元素的访问,但是在nhibernate中还是必须要提供索引。这样就出现一个问题:如果表中没有这样的index字段,将无法使用array,这样可能降低性能,因为使用IList的时候需要 boxing 和unboxing。
   
        另外,在使用的过程中发现使用 list无法与datagrid绑定,而bag却可以。
       <bag name="Students" lazy="true" inverse="true"  >
          <key column="TeacherID"/>
          <one-to-many class="testMSSql.student, testMSSql" />
        </bag>

       <list name="Students" lazy="true" inverse="true"  >
          <key column="TeacherID"/> 
          <index column="id" />
          <one-to-many class="testMSSql.student, testMSSql" />
        </list>
                       
    

posted on 2004-06-30 12:38  wljcan  阅读(3331)  评论(8编辑  收藏  举报

导航