which is the SQL you can write to sole your problem ?

On Wed, Aug 18, 2010 at 8:20 AM, sasha revzin <[email protected]> wrote:

> not good, what if i will have ~10 columns that need be returned with
> product?
>
> i will need to add them in group by
>
> i asked it already in stackoverflow:
> http://stackoverflow.com/questions/3500395/how-can-i-perform-this-query-in-nhibernate-for-getting-child-count
>
> but looks like nobody has an answer for simple question :(
>
> On Wed, Aug 18, 2010 at 14:05, Fabio Maulo <[email protected]> wrote:
>
>> group by
>>
>> On Wed, Aug 18, 2010 at 1:30 AM, sasha revzin <[email protected]>wrote:
>>
>>> no, this code will return me count of specific category:
>>>
>>> select count(*) from products p inner join categories c on
>>> p.category_Id=c.Id where c.Id=1
>>>
>>> but what i need is category list with extra column that calculate product
>>> count for each category
>>>
>>>
>>> On Tue, Aug 17, 2010 at 14:28, José F. Romaniello <
>>> [email protected]> wrote:
>>>
>>>> You started wrong. If you are going to count Products, you should start
>>>> with Products:
>>>>
>>>> CurrentSession.CreateCriteria<Product>()
>>>> .CreateAlias("Category", "cat")
>>>>  .Add(Restrictions.Eq("cat.Id", 1))
>>>> .SetProjection(Projections.RowCount())
>>>>  .UniqueResult<int>();
>>>>
>>>>
>>>> I am not really sure about the last part.
>>>>
>>>>
>>>> 2010/8/17 Sasha <[email protected]>
>>>>
>>>> select name,
>>>>> (select count(*) from products where
>>>>> products.category_Id=categories.Id) as productCount
>>>>> from categories
>>>>>
>>>>> starting with:
>>>>> session.CreateCriteria<Category>()
>>>>>
>>>>> but whats next?
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "nhusers" group.
>>>>> To post to this group, send email to [email protected].
>>>>> To unsubscribe from this group, send email to
>>>>> [email protected]<nhusers%[email protected]>
>>>>> .
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/group/nhusers?hl=en.
>>>>>
>>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "nhusers" group.
>>>> To post to this group, send email to [email protected].
>>>> To unsubscribe from this group, send email to
>>>> [email protected]<nhusers%[email protected]>
>>>> .
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/nhusers?hl=en.
>>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "nhusers" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected]<nhusers%[email protected]>
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/nhusers?hl=en.
>>>
>>
>>
>>
>> --
>> Fabio Maulo
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "nhusers" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<nhusers%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/nhusers?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>



-- 
Fabio Maulo

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to