using System; using System.Collections.Generic; using System.Text; namespace Northwind.Domain { class CategorySearchCriteria:ISearchCriteria { /// <summary> /// Generally, it is a better idea to store all of your default values in a more central location, /// but we will be storing them here for the sake of simplicity /// </summary> #region defaults private static readonly int defaultID = -1; private static readonly bool defaultExcludeCategoriesWithProducts = false; #endregion #region members private int id = defaultID; private bool excludeCategoriesWithProducts = defaultExcludeCategoriesWithProducts; #endregion #region properties /// <summary> /// Search for a specific Category ID /// </summary> public int Id { get { return id; } set { id = value; } } /// <summary> /// Use this to search only within the realm of categories without any products /// </summary> public bool ExcludeCategoriesWithProducts { get { return excludeCategoriesWithProducts; } set { excludeCategoriesWithProducts = value; } } #endregion #region HQL public string HQL { get { //select new Category(c.Id, c.CategoryName, count(p)) from Category c join c.Products p group by c.Id, c.CategoryName order by count(p) StringBuilder builder = new StringBuilder("select cat from Category cat where (1=1) "); if (id != defaultID) builder.Append(" and cat.ID = '" + id + "'"); if (excludeCategoriesWithProducts != defaultExcludeCategoriesWithProducts) builder.Append(" and cat.Id not in (select p.Category.Id from Product p) "); return builder.ToString(); } } #endregion } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)