如何在NHibernate中执行此查询以获取子计数

时间:2010-08-17 07:53:32

标签: performance nhibernate criteria

select name, 
(select count(*) from products where products.category_Id=categories.Id) as productCount
from categories

session.CreateCriteria<Category>()

但接下来呢?

我甚至不知道如何在Google上搜索它?

1 个答案:

答案 0 :(得分:1)

想想你的查询

SELECT     categories.Id, count(categories.Id)
FROM         categories inner join products on products.category_Id=categories.Id
group by categories.Id

我认为他们会产生相同的结果。

搜索谷歌

  

nhibernate criteria join

  

CreateAlias