mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Fix/8439 hql sort factory (#8440)
* Additional methods to extend the sort capabilities for projections * Added some comments
This commit is contained in:
@@ -251,8 +251,14 @@ namespace Orchard.ContentManagement {
|
|||||||
sort.Item2(sortFactory);
|
sort.Item2(sortFactory);
|
||||||
|
|
||||||
if (!sortFactory.Randomize) {
|
if (!sortFactory.Randomize) {
|
||||||
sb.Append(", ");
|
if (!string.IsNullOrWhiteSpace(sortFactory.PropertyName)) {
|
||||||
sb.Append(sort.Item1.Name).Append(".").Append(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 {
|
else {
|
||||||
// select distinct can't be used with newid()
|
// select distinct can't be used with newid()
|
||||||
@@ -325,9 +331,16 @@ namespace Orchard.ContentManagement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sb.Append(sort.Item1.Name).Append(".").Append(sortFactory.PropertyName);
|
if (!string.IsNullOrWhiteSpace(sortFactory.AdditionalOrderByStatement)) {
|
||||||
if (!sortFactory.Ascending) {
|
sb.Append(sortFactory.AdditionalOrderByStatement);
|
||||||
sb.Append(" desc");
|
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 bool Ascending { get; set; }
|
||||||
public string PropertyName { get; set; }
|
public string PropertyName { get; set; }
|
||||||
public bool Randomize { get; set; }
|
public bool Randomize { get; set; }
|
||||||
|
public string AdditionalSelectStatement { get; set; }
|
||||||
|
public string AdditionalOrderByStatement { get; set; }
|
||||||
|
|
||||||
public void Asc(string propertyName) {
|
public void Asc(string propertyName) {
|
||||||
PropertyName = propertyName;
|
PropertyName = propertyName;
|
||||||
@@ -468,6 +483,18 @@ namespace Orchard.ContentManagement {
|
|||||||
public void Random() {
|
public void Random() {
|
||||||
Randomize = true;
|
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{
|
public class DefaultAliasFactory : IAliasFactory{
|
||||||
|
|||||||
@@ -192,6 +192,32 @@ namespace Orchard.ContentManagement {
|
|||||||
/// Sorts randomly
|
/// Sorts randomly
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void Random();
|
void Random();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sort in ascending order, adding custom HQL strings
|
||||||
|
/// to the SELECT and ORDER BY statements
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="propertyName">Name of the property</param>
|
||||||
|
/// <param name="additionalSelectOps">Additional HQL for the SELECT statement</param>
|
||||||
|
/// <param name="additionalOrderOps">Additional HQL for the ORDER BY statement</param>
|
||||||
|
/// <remarks>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.</remarks>
|
||||||
|
void Asc(string propertyName, string additionalSelectOps, string additionalOrderOps);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sort in descending order, adding custom HQL strings
|
||||||
|
/// to the SELECT and ORDER BY statements
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="propertyName">Name of the property</param>
|
||||||
|
/// <param name="additionalSelectOps">Additional HQL for the SELECT statement</param>
|
||||||
|
/// <param name="additionalOrderOps">Additional HQL for the ORDER BY statement</param>
|
||||||
|
/// <remarks>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.</remarks>
|
||||||
|
void Desc(string propertyName, string additionalSelectOps, string additionalOrderOps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user