Reputation: 63
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
Upvotes: 5
Views: 1316
Reputation: 17955
You can either do what sJhonny recommends or use the lazy="extra"
attribute on the mapping. That way you can just do Posts.Count to get just the count without loading all of the entities.
See this SO question: NHibernate Lazy="Extra"
Upvotes: 3
Reputation: 6752
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
Upvotes: 3