|
I have a set of Items organized by Category and I want to get a count of Items per Category for display on a web page.
This is a VERY simplified table structure:
=======
Category
-----------
CategoryID (PK)
Name
URL (UK)
=======
========
Item
----------
ItemID (PK)
CategoryID (FK)
IsPublished
ItemType (enum, vals are A, B, and C)
=========
So, I have one page for each ItemType with a list of all Categories. The list is just the names linked to a page that shows all Items in that Category whose ItemType matches the page it came from and where IsPublished is 1 (true). So the category page URL might be /Category.aspx?ItemType=B and the page with the list of items might be /Category.aspx?ItemType=B&CategoryID=42
What I want to be able to do is on the category list page (/Category.aspx?ItemType=B) be able to put the number of Items in parenthesis next to the category name link.
I know there are several ways to do this and my problem is not getting it done. My problem is I'm not sure which way is the correct/best way to do it.
Ways I have thought of to solve this problem:
1. Direct SQL query
2. HQL query
3. Add three properties to the Category object: CountOfItemTypeA, CountOfItemTypeB, and CountOfItemTypeC. The load the counts in the mapping for the Category object. (Before you balk at this, A, B, and C are definitely the only possible values. It would take a huge shift in the business for this situation to change and so I am comfortable with doing it this way.)
4. Possibly use a Criteria query??
5. My Category object already has a bag of ItemTypeAList, etc. Does it work to just do Category.ItemTypeAList.Count or is that inefficient?
6. Any better solutions out there???
So, what do you think the best overall solution to this problem is?
TIA
_________________ Josh Coady
http://jlcoady.net/
|