• 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>
                           
        
  • 相关阅读:
    TCP/IP四层模型
    Java编程题
    大整数阶乘的运算(可以计算1000!) .
    sleep和wait的区别
    Javascript保留字(Javascript Reserved Words)
    WEBLOGIC 内存溢出 解决方案
    Java学习的30个目标以及系统架构师推荐的书
    笔记分析
    MySQL分区(Partition)功能试验
    Java线程:生产者消费者模型
  • 原文地址:https://www.cnblogs.com/wljcan/p/19713.html
Copyright © 2020-2023  润新知