代码之家  ›  专栏  ›  技术社区  ›  marshally

使用NHibernate 2.0.1实现类似于lazy=“extra”功能的最佳方法

  •  5
  • marshally  · 技术社区  · 17 年前

    在Hibernate 3.0中,有一个lazy=“extra”特性,允许您检查集合属性的子集,而无需延迟加载整个集合。

    不幸的是,在NHibernate2.1之前,这项功能将不可用,而NHibernate2.1仍处于Alpha版本。 http://jira.nhibernate.org/browse/NH-855

    如何使用NHibernate 2.0.1实现这一点?

    我以前有像这样的特殊属性

    <property name="ChildCollectionCount" type="int" formula="(select count(*) from ChildTable child where child.parentID = parentID "/>
    

    但是我不能再使用这些了,因为我现在正在共享这个库,这对其他用户来说是一个性能问题。

    3 回复  |  直到 17 年前
        1
  •  0
  •   Chris Kimpton    17 年前

        2
  •  0
  •   Jaguar    16 年前

    很晚,但您可以对集合应用筛选器

    IQuery q = nhSession.CreateFilter(Parent.ChildCollection, "select count(*)");
    long countResult = q.UniqueResult<long>();
    

        3
  •  0
  •   Noel Kennedy    16 年前

    我建议使用单独的查询,而不是域关系。然后你可以使用各种各样的优化。