【问题标题】:How to select count in NHibernate HQL when joining tables连接表时如何在 NHibernate HQL 中选择计数
【发布时间】:2013-06-04 13:31:37
【问题描述】:

NHibernate 为什么要翻译这个 HQL:

select count(*) from TeacherResource as tr
    inner join fetch tr.Product as pr
    where pr.CatalogTitle like '%ame%'

进入这个无效的 SQL(包括 where 子句但省略了表连接):

select count(*) as col_0_0_
    from   TeacherResources teacherres0_
    where  product1_.CatalogTitle like '%ame%'

以及如何执行符合预期的计数?

这是实体的相关部分:

Public Class TeacherResource
    Public Overridable Property TeacherResourceId As Guid
    Public Overridable Property Product As BvCustomProduct
End Class

和映射:

<class name="TeacherResource" table="TeacherResources">
    <id name="TeacherResourceId">
        <generator class="guid"/>
    </id>
    <many-to-one name="Product" column="ProductBvin"/>
</class>

【问题讨论】:

  • 我们可以看看你的映射吗? tr.Product 是收藏吗?
  • 这是一个单一的实体。我已经添加了映射。

标签: nhibernate hql


【解决方案1】:

您不需要显式连接,也不需要为您的查询提取数据。

这就够了:

select count(*)
from TeacherResource
Where Product.CatalogTitle like '%ame%'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-12
    • 1970-01-01
    相关资源
    最近更新 更多