diff --git a/src/Orchard/ContentManagement/DefaultHqlQuery.cs b/src/Orchard/ContentManagement/DefaultHqlQuery.cs
index 92d630b20..99e4ed8e9 100644
--- a/src/Orchard/ContentManagement/DefaultHqlQuery.cs
+++ b/src/Orchard/ContentManagement/DefaultHqlQuery.cs
@@ -251,8 +251,14 @@ namespace Orchard.ContentManagement {
sort.Item2(sortFactory);
if (!sortFactory.Randomize) {
- sb.Append(", ");
- sb.Append(sort.Item1.Name).Append(".").Append(sortFactory.PropertyName);
+ if (!string.IsNullOrWhiteSpace(sortFactory.PropertyName)) {
+ sb.Append(", ");
+ sb.Append(sort.Item1.Name).Append(".").Append(sortFactory.PropertyName);
+ }
+ if (!string.IsNullOrWhiteSpace(sortFactory.AdditionalSelectStatement)) {
+ sb.Append(", ");
+ sb.Append(sortFactory.AdditionalSelectStatement);
+ }
}
else {
// select distinct can't be used with newid()
@@ -325,9 +331,16 @@ namespace Orchard.ContentManagement {
}
}
else {
- sb.Append(sort.Item1.Name).Append(".").Append(sortFactory.PropertyName);
- if (!sortFactory.Ascending) {
- sb.Append(" desc");
+ if (!string.IsNullOrWhiteSpace(sortFactory.AdditionalOrderByStatement)) {
+ sb.Append(sortFactory.AdditionalOrderByStatement);
+ if (!sortFactory.Ascending) {
+ sb.Append(" desc");
+ }
+ } else if (!string.IsNullOrWhiteSpace(sortFactory.PropertyName)) {
+ sb.Append(sort.Item1.Name).Append(".").Append(sortFactory.PropertyName);
+ if (!sortFactory.Ascending) {
+ sb.Append(" desc");
+ }
}
}
}
@@ -454,6 +467,8 @@ namespace Orchard.ContentManagement {
public bool Ascending { get; set; }
public string PropertyName { get; set; }
public bool Randomize { get; set; }
+ public string AdditionalSelectStatement { get; set; }
+ public string AdditionalOrderByStatement { get; set; }
public void Asc(string propertyName) {
PropertyName = propertyName;
@@ -468,6 +483,18 @@ namespace Orchard.ContentManagement {
public void Random() {
Randomize = true;
}
+
+ public void Asc(string propertyName, string additionalSelectOps, string additionalOrderOps) {
+ Asc(propertyName);
+ AdditionalSelectStatement = additionalSelectOps;
+ AdditionalOrderByStatement = additionalOrderOps;
+ }
+
+ public void Desc(string propertyName, string additionalSelectOps, string additionalOrderOps) {
+ Desc(propertyName);
+ AdditionalSelectStatement = additionalSelectOps;
+ AdditionalOrderByStatement = additionalOrderOps;
+ }
}
public class DefaultAliasFactory : IAliasFactory{
diff --git a/src/Orchard/ContentManagement/IHqlQuery.cs b/src/Orchard/ContentManagement/IHqlQuery.cs
index 4b4250b7b..1b2431bba 100644
--- a/src/Orchard/ContentManagement/IHqlQuery.cs
+++ b/src/Orchard/ContentManagement/IHqlQuery.cs
@@ -192,6 +192,32 @@ namespace Orchard.ContentManagement {
/// Sorts randomly
///
void Random();
+
+ ///
+ /// Sort in ascending order, adding custom HQL strings
+ /// to the SELECT and ORDER BY statements
+ ///
+ /// Name of the property
+ /// Additional HQL for the SELECT statement
+ /// Additional HQL for the ORDER BY statement
+ /// ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
+ /// If such query is being generated by the implementation (as is the case for DefaultHqlQuery),
+ /// make sure to respect that constraint when generating the addtionalOrderOps and
+ /// additionalSelectOps parameters.
+ void Asc(string propertyName, string additionalSelectOps, string additionalOrderOps);
+
+ ///
+ /// Sort in descending order, adding custom HQL strings
+ /// to the SELECT and ORDER BY statements
+ ///
+ /// Name of the property
+ /// Additional HQL for the SELECT statement
+ /// Additional HQL for the ORDER BY statement
+ /// ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
+ /// If such query is being generated by the implementation (as is the case for DefaultHqlQuery),
+ /// make sure to respect that constraint when generating the addtionalOrderOps and
+ /// additionalSelectOps parameters.
+ void Desc(string propertyName, string additionalSelectOps, string additionalOrderOps);
}
}