mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-03 03:58:13 +08:00
Fixing compatibility with previous IContentQuery.OrderBy methods
--HG-- branch : NH3
This commit is contained in:
@@ -4,12 +4,10 @@ using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection.Emit;
|
||||
using FluentNHibernate;
|
||||
using NHibernate;
|
||||
using NHibernate.Criterion;
|
||||
using Orchard.ContentManagement.Records;
|
||||
using Orchard.Data;
|
||||
using Orchard.Utility.Extensions;
|
||||
using NHibernate.Transform;
|
||||
using NHibernate.SqlCommand;
|
||||
using Expression = System.Linq.Expressions.Expression;
|
||||
@@ -38,20 +36,20 @@ namespace Orchard.ContentManagement {
|
||||
return _session;
|
||||
}
|
||||
|
||||
IQueryOver<ContentItemVersionRecord, TRecord> BindQueryOverByPath<TRecord, U>(IQueryOver<ContentItemVersionRecord, U> queryOver, string name) {
|
||||
IQueryOver<ContentItemVersionRecord, TRecord> BindQueryOverByPath<TRecord, TU>(IQueryOver<ContentItemVersionRecord, TU> queryOver, string name) {
|
||||
if (_joins.ContainsKey(typeof(TRecord).Name)) {
|
||||
return (IQueryOver<ContentItemVersionRecord, TRecord>)_joins[typeof(TRecord).Name];
|
||||
}
|
||||
|
||||
// public TPartRecord TPartRecord {get;set;}
|
||||
var dynamicMethod = new DynamicMethod(name, typeof(TRecord), null, typeof(U));
|
||||
var syntheticMethod = new ContentItemAlteration.SyntheticMethodInfo(dynamicMethod, typeof(U));
|
||||
var dynamicMethod = new DynamicMethod(name, typeof(TRecord), null, typeof(TU));
|
||||
var syntheticMethod = new ContentItemAlteration.SyntheticMethodInfo(dynamicMethod, typeof(TU));
|
||||
var syntheticProperty = new ContentItemAlteration.SyntheticPropertyInfo(syntheticMethod);
|
||||
|
||||
// record => record.TPartRecord
|
||||
var parameter = Expression.Parameter(typeof(U), "record");
|
||||
var syntheticExpression = (Expression<Func<U, TRecord>>)Expression.Lambda(
|
||||
typeof(Func<U, TRecord>),
|
||||
var parameter = Expression.Parameter(typeof(TU), "record");
|
||||
var syntheticExpression = (Expression<Func<TU, TRecord>>)Expression.Lambda(
|
||||
typeof(Func<TU, TRecord>),
|
||||
Expression.Property(parameter, syntheticProperty),
|
||||
parameter);
|
||||
|
||||
@@ -116,6 +114,24 @@ namespace Orchard.ContentManagement {
|
||||
BindPartQueryOver<TRecord>().OrderBy(keySelector).Desc();
|
||||
}
|
||||
|
||||
private void OrderBy<TRecord, TKey>(Expression<Func<TRecord, TKey>> keySelector) where TRecord : ContentPartRecord {
|
||||
BindPartQueryOver<TRecord>().OrderBy(AddBox(keySelector)).Asc();
|
||||
}
|
||||
|
||||
private void OrderByDescending<TRecord, TKey>(Expression<Func<TRecord, TKey>> keySelector) where TRecord : ContentPartRecord {
|
||||
BindPartQueryOver<TRecord>().OrderBy(AddBox(keySelector)).Desc();
|
||||
}
|
||||
|
||||
private static Expression<Func<TInput, object>> AddBox<TInput, TOutput>
|
||||
(Expression<Func<TInput, TOutput>> expression) {
|
||||
// Add the boxing operation, but get a weakly typed expression
|
||||
Expression converted = Expression.Convert
|
||||
(expression.Body, typeof(object));
|
||||
// Use Expression.Lambda to get back to strong typing
|
||||
return Expression.Lambda<Func<TInput, object>>
|
||||
(converted, expression.Parameters);
|
||||
}
|
||||
|
||||
private IEnumerable<ContentItem> Slice(int skip, int count) {
|
||||
var queryOver = BindItemVersionQueryOver();
|
||||
|
||||
@@ -205,6 +221,16 @@ namespace Orchard.ContentManagement {
|
||||
_query.OrderByDescending(keySelector);
|
||||
return new ContentQuery<T, TRecord>(_query);
|
||||
}
|
||||
|
||||
IContentQuery<T, TRecord> IContentQuery<T>.OrderBy<TRecord, TKey>(Expression<Func<TRecord, TKey>> keySelector) {
|
||||
_query.OrderBy(AddBox(keySelector));
|
||||
return new ContentQuery<T, TRecord>(_query);
|
||||
}
|
||||
|
||||
IContentQuery<T, TRecord> IContentQuery<T>.OrderByDescending<TRecord, TKey>(Expression<Func<TRecord, TKey>> keySelector) {
|
||||
_query.OrderByDescending(AddBox(keySelector));
|
||||
return new ContentQuery<T, TRecord>(_query);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -225,6 +251,16 @@ namespace Orchard.ContentManagement {
|
||||
return this;
|
||||
}
|
||||
|
||||
IContentQuery<T, TR> IContentQuery<T, TR>.OrderBy<TKey>(Expression<Func<TR, TKey>> keySelector) {
|
||||
_query.OrderBy(keySelector);
|
||||
return this;
|
||||
}
|
||||
|
||||
IContentQuery<T, TR> IContentQuery<T, TR>.OrderByDescending<TKey>(Expression<Func<TR, TKey>> keySelector) {
|
||||
_query.OrderByDescending(keySelector);
|
||||
return this;
|
||||
}
|
||||
|
||||
IContentQuery<T, TR> IContentQuery<T, TR>.OrderBy(Expression<Func<TR, object>> keySelector) {
|
||||
_query.OrderBy(keySelector);
|
||||
return this;
|
||||
|
||||
@@ -23,6 +23,9 @@ namespace Orchard.ContentManagement {
|
||||
IContentQuery<TPart, TRecord> Where<TRecord>(Expression<Func<TRecord, bool>> predicate) where TRecord : ContentPartRecord;
|
||||
IContentQuery<TPart, TRecord> OrderBy<TRecord>(Expression<Func<TRecord, object>> keySelector) where TRecord : ContentPartRecord;
|
||||
IContentQuery<TPart, TRecord> OrderByDescending<TRecord>(Expression<Func<TRecord, object>> keySelector) where TRecord : ContentPartRecord;
|
||||
|
||||
[Obsolete]IContentQuery<TPart, TRecord> OrderBy<TRecord, TKey>(Expression<Func<TRecord, TKey>> keySelector) where TRecord : ContentPartRecord;
|
||||
[Obsolete]IContentQuery<TPart, TRecord> OrderByDescending<TRecord, TKey>(Expression<Func<TRecord, TKey>> keySelector) where TRecord : ContentPartRecord;
|
||||
}
|
||||
|
||||
public interface IContentQuery<TPart, TRecord> : IContentQuery<TPart> where TPart : IContent where TRecord : ContentPartRecord {
|
||||
@@ -32,6 +35,9 @@ namespace Orchard.ContentManagement {
|
||||
IContentQuery<TPart, TRecord> OrderBy(Expression<Func<TRecord, object>> keySelector);
|
||||
IContentQuery<TPart, TRecord> OrderByDescending(Expression<Func<TRecord, object>> keySelector);
|
||||
|
||||
[Obsolete] IContentQuery<TPart, TRecord> OrderBy<TKey>(Expression<Func<TRecord, TKey>> keySelector);
|
||||
[Obsolete] IContentQuery<TPart, TRecord> OrderByDescending<TKey>(Expression<Func<TRecord, TKey>> keySelector);
|
||||
|
||||
IContentQuery<TPart, TRecord> WithQueryHints(QueryHints hints);
|
||||
IContentQuery<TPart, TRecord> WithQueryHintsFor(string contentType);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user