3
votes

I wonder if this can be resolved with less overhead: Given a simple one-to-many relationship Product --> Size (Product has got one size). In order to figure out how many products are assigned to a size I would update the mapping of Size with a Product-Bag. But what if I am only interested in the count (no need for any product details), can this be done without the overhead of loading all the product-objects?

Thx for any tipps sl3dg3

2

2 Answers

7
votes

Use attribute lazy="extra" in hbm or ExtraLazyLoad() in fluent mappings for Product collection. With extra lazy loading Products.Count translates into sql 'select count'

See corresponding question

-1
votes

Why not create a query? Something like this for Linq (of course HQL, criteria or QueryOver should work too):

int count = session.Query<Product>()
    .Where(x => x.Size != null)
    .Count();