Exemple #1
0
        /// <summary>
        /// Extracts a list of <see cref="HqlCondition"/> objects from the specified <see cref="SearchCriteria"/>
        /// </summary>
        /// <param name="qualifier">The HQL qualifier to prepend to the criteria variables</param>
        /// <param name="criteria">The search criteria object</param>
        /// <param name="remapHqlExprFunc"></param>
        /// <returns>A list of HQL conditions that are equivalent to the search criteria</returns>
        public static HqlCondition[] FromSearchCriteria(string qualifier, SearchCriteria criteria, Converter <string, string> remapHqlExprFunc)
        {
            var hqlConditions = new List <HqlCondition>();

            if (criteria is SearchConditionBase)
            {
                var sc = (SearchConditionBase)criteria;
                if (sc.Test != SearchConditionTest.None)
                {
                    hqlConditions.Add(GetCondition(remapHqlExprFunc(qualifier), sc.Test, sc.Values));
                }
            }
            else
            {
                // recur on subCriteria
                foreach (var subCriteria in criteria.EnumerateSubCriteria())
                {
                    // use a different syntax for "extended properties" than regular properties
                    var subQualifier = criteria is ExtendedPropertiesSearchCriteria?
                                       string.Format("{0}['{1}']", qualifier, subCriteria.GetKey()) :
                                           string.Format("{0}.{1}", qualifier, subCriteria.GetKey());

                    hqlConditions.AddRange(FromSearchCriteria(subQualifier, subCriteria, remapHqlExprFunc));
                }
            }

            return(hqlConditions.ToArray());
        }
Exemple #2
0
		/// <summary>
		/// Extracts a list of <see cref="HqlCondition"/> objects from the specified <see cref="SearchCriteria"/>
		/// </summary>
		/// <param name="qualifier">The HQL qualifier to prepend to the criteria variables</param>
		/// <param name="criteria">The search criteria object</param>
		/// <param name="remapHqlExprFunc"></param>
		/// <returns>A list of HQL conditions that are equivalent to the search criteria</returns>
		public static HqlCondition[] FromSearchCriteria(string qualifier, SearchCriteria criteria, Converter<string, string> remapHqlExprFunc)
		{
			var hqlConditions = new List<HqlCondition>();
			if (criteria is SearchConditionBase)
			{
				var sc = (SearchConditionBase)criteria;
				if (sc.Test != SearchConditionTest.None)
				{
					hqlConditions.Add(GetCondition(remapHqlExprFunc(qualifier), sc.Test, sc.Values));
				}
			}
			else
			{
				// recur on subCriteria
				foreach (var subCriteria in criteria.EnumerateSubCriteria())
				{
					// use a different syntax for "extended properties" than regular properties
					var subQualifier = criteria is ExtendedPropertiesSearchCriteria ?
						string.Format("{0}['{1}']", qualifier, subCriteria.GetKey()) :
						string.Format("{0}.{1}", qualifier, subCriteria.GetKey());

					hqlConditions.AddRange(FromSearchCriteria(subQualifier, subCriteria, remapHqlExprFunc));
				}
			}

			return hqlConditions.ToArray();
		}
Exemple #3
0
        /// <summary>
        /// Extracts a list of <see cref="HqlSort"/> objects from the specified <see cref="SearchCriteria"/>
        /// </summary>
        /// <param name="qualifier">The HQL qualifier to prepend to the sort variables</param>
        /// <param name="criteria">The search criteria object</param>
        /// <param name="remapHqlExprFunc"></param>
        /// <returns>A list of HQL sort object that are equivalent to the specified criteria</returns>
        public static HqlSort[] FromSearchCriteria(string qualifier, SearchCriteria criteria, Converter <string, string> remapHqlExprFunc)
        {
            var hqlSorts = new List <HqlSort>();

            if (criteria is SearchConditionBase)
            {
                var sc = (SearchConditionBase)criteria;
                if (sc.SortPosition > -1)
                {
                    hqlSorts.Add(new HqlSort(remapHqlExprFunc(qualifier), sc.SortDirection, sc.SortPosition));
                }
            }
            else
            {
                // recur on subCriteria
                foreach (var subCriteria in criteria.EnumerateSubCriteria())
                {
                    var subQualifier = string.Format("{0}.{1}", qualifier, subCriteria.GetKey());
                    hqlSorts.AddRange(FromSearchCriteria(subQualifier, subCriteria, remapHqlExprFunc));
                }
            }

            return(hqlSorts.ToArray());
        }