zoukankan      html  css  js  c++  java
  • 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>
                           
        
  • 相关阅读:
    语音合成
    JAVA的18条BASE
    Java关键字final、static使用总结
    JAVA学习之路:不走弯路,就是捷径
    每个java初学者都应该搞懂的问题
    Tomcat5.5.9+JSP经典配置实例
    FineUI控件集合
    AngularJS基础
    数据库优化方案之SQL脚本优化
    数据库分库分表策略之MS-SQL读写分离方案
  • 原文地址:https://www.cnblogs.com/wljcan/p/19713.html
Copyright © 2011-2022 走看看