0

为什么 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>
4

1 回答 1

1

您不需要显式连接,也不需要获取查询。

这应该足够了:

select count(*)
from TeacherResource
Where Product.CatalogTitle like '%ame%'
于 2013-06-04T16:49:10.587 回答