One-To-Many Count

浪尽此生 提交于 2019-12-22 10:17:05

问题


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


回答1:


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




回答2:


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


来源:https://stackoverflow.com/questions/5962407/one-to-many-count

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!