mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-06-28 15:34:39 +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:
parent
0cadd5a916
commit
eebb22edbf
@ -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{
|
||||
|
@ -192,6 +192,32 @@ namespace Orchard.ContentManagement {
|
||||
/// Sorts randomly
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user