开发者

One-To-Many Count

I wonder if this can be resolved with less overhead: Given a simple one-to-many relationship Product --> Size (Pro开发者_C百科duct 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


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


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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜