3

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

cvsguimaraes
  • 12,910
  • 9
  • 49
  • 73
sl3dg3
  • 5,026
  • 12
  • 50
  • 74

2 Answers2

7

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

Community
  • 1
  • 1
jjjjj
  • 339
  • 4
  • 11
-1

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();
cremor
  • 6,669
  • 1
  • 29
  • 72