views:

32

answers:

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

session.CreateCriteria<Category>()

but whats next?

i don't even know how to search it in Google?

+1  A: 

think of your query like

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

I think they will produce the same result.

search google for

nhibernate criteria join

and

CreateAlias

Circadian
i think that it should be better solution then inner join, any way it should be left join, cuz i dont wanna miss categories these haven't any product
msony
you are right about both. the only reason i rewrote your query is because it will be easier to translate to nhibernate that way.
Circadian