Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Knowing child collections count without loading them in NHIbernate

I'm using NHibernate with FluentNH. I've a simple class called PostCategory and it contains a collection of Posts. The PostCategory class contains a property called TotalActivePosts. When I load all the PostCategories I want the no. of active posts for each category to be populated in this property. How I can do that? Any help is greatly appreciated.

Vijaya Anand

like image 332
Vijaya Anand Avatar asked May 14 '11 12:05

Vijaya Anand


1 Answers

The way I did it is by using a computed property. see item no. 5- arbitrary SQL.
you could use something like:

Select Count(*) from Posts where PostCategoryId = Id And IsActive = 1    

see also this question

like image 64
J. Ed Avatar answered Sep 27 '22 19:09

J. Ed