为什么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>
答案 0 :(得分:1)
您不需要显式连接,也不需要获取查询。
这应该足够了:
select count(*)
from TeacherResource
Where Product.CatalogTitle like '%ame%'