mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Allwing the content manager to get an optional set of predicates
--HG-- branch : 1.x
This commit is contained in:
@@ -75,21 +75,36 @@ namespace Orchard.ContentManagement {
|
|||||||
BindPartCriteria<TRecord>();
|
BindPartCriteria<TRecord>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Where<TRecord>(Expression<Func<TRecord, bool>> predicate) where TRecord : ContentPartRecord {
|
private void Where<TRecord>(Expression<Func<TRecord, bool>> predicate, params Expression<Func<TRecord, bool>>[] orPredicates) where TRecord : ContentPartRecord {
|
||||||
|
|
||||||
// build a linq to nhibernate expression
|
|
||||||
var options = new QueryOptions();
|
|
||||||
var queryProvider = new NHibernateQueryProvider(BindSession(), options);
|
|
||||||
var queryable = new Query<TRecord>(queryProvider, options).Where(predicate);
|
|
||||||
|
|
||||||
// translate it into the nhibernate ICriteria implementation
|
|
||||||
var criteria = (CriteriaImpl)queryProvider.TranslateExpression(queryable.Expression);
|
|
||||||
|
|
||||||
// attach the criterion from the predicate to this query's criteria for the record
|
// attach the criterion from the predicate to this query's criteria for the record
|
||||||
var recordCriteria = BindPartCriteria<TRecord>();
|
var recordCriteria = BindPartCriteria<TRecord>();
|
||||||
foreach (var expressionEntry in criteria.IterateExpressionEntries()) {
|
var predicates = Enumerable
|
||||||
recordCriteria.Add(expressionEntry.Criterion);
|
.Empty<Expression<Func<TRecord, bool>>>()
|
||||||
|
.Union(new []{predicate})
|
||||||
|
.Union(orPredicates);
|
||||||
|
|
||||||
|
var disjunction = Restrictions.Disjunction();
|
||||||
|
|
||||||
|
foreach (var p in predicates) {
|
||||||
|
// build a linq to nhibernate expression
|
||||||
|
var options = new QueryOptions();
|
||||||
|
var queryProvider = new NHibernateQueryProvider(BindSession(), options);
|
||||||
|
|
||||||
|
var queryable = new Query<TRecord>(queryProvider, options).Where(p);
|
||||||
|
var conjunction = Restrictions.Conjunction();
|
||||||
|
|
||||||
|
// translate it into the nhibernate ICriteria implementation
|
||||||
|
var criteria = (CriteriaImpl) queryProvider.TranslateExpression(queryable.Expression);
|
||||||
|
|
||||||
|
foreach (var expressionEntry in criteria.IterateExpressionEntries()) {
|
||||||
|
conjunction.Add(expressionEntry.Criterion);
|
||||||
|
}
|
||||||
|
|
||||||
|
disjunction.Add(conjunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
recordCriteria.Add(disjunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Where(Action<IExpressionFactory> expression) {
|
private void Where(Action<IExpressionFactory> expression) {
|
||||||
@@ -220,8 +235,8 @@ namespace Orchard.ContentManagement {
|
|||||||
return new ContentQuery<T>(_query);
|
return new ContentQuery<T>(_query);
|
||||||
}
|
}
|
||||||
|
|
||||||
IContentQuery<T, TRecord> IContentQuery<T>.Where<TRecord>(Expression<Func<TRecord, bool>> predicate) {
|
IContentQuery<T, TRecord> IContentQuery<T>.Where<TRecord>(Expression<Func<TRecord, bool>> predicate, params Expression<Func<TRecord, bool>>[] orPredicates) {
|
||||||
_query.Where(predicate);
|
_query.Where(predicate, orPredicates);
|
||||||
return new ContentQuery<T, TRecord>(_query);
|
return new ContentQuery<T, TRecord>(_query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,8 +268,8 @@ namespace Orchard.ContentManagement {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IContentQuery<T, TR> IContentQuery<T, TR>.Where(Expression<Func<TR, bool>> predicate) {
|
IContentQuery<T, TR> IContentQuery<T, TR>.Where(Expression<Func<TR, bool>> predicate, params Expression<Func<TR, bool>>[] orPredicates) {
|
||||||
_query.Where(predicate);
|
_query.Where(predicate, orPredicates);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace Orchard.ContentManagement {
|
|||||||
IContentQuery<TPart, TRecord> Join<TRecord>() where TRecord : ContentPartRecord;
|
IContentQuery<TPart, TRecord> Join<TRecord>() where TRecord : ContentPartRecord;
|
||||||
|
|
||||||
IContentQuery<TPart> Where(Action<IExpressionFactory> predicate);
|
IContentQuery<TPart> Where(Action<IExpressionFactory> predicate);
|
||||||
IContentQuery<TPart, TRecord> Where<TRecord>(Expression<Func<TRecord, bool>> predicate) where TRecord : ContentPartRecord;
|
IContentQuery<TPart, TRecord> Where<TRecord>(Expression<Func<TRecord, bool>> predicate, params Expression<Func<TRecord, bool>>[] orPredicates) where TRecord : ContentPartRecord;
|
||||||
|
|
||||||
IContentQuery<TPart> OrderBy(Action<ISortFactory> order);
|
IContentQuery<TPart> OrderBy(Action<ISortFactory> order);
|
||||||
IContentQuery<TPart, TRecord> OrderBy<TRecord, TKey>(Expression<Func<TRecord, TKey>> keySelector) where TRecord : ContentPartRecord;
|
IContentQuery<TPart, TRecord> OrderBy<TRecord, TKey>(Expression<Func<TRecord, TKey>> keySelector) where TRecord : ContentPartRecord;
|
||||||
@@ -31,7 +31,7 @@ namespace Orchard.ContentManagement {
|
|||||||
public interface IContentQuery<TPart, TRecord> : IContentQuery<TPart> where TPart : IContent where TRecord : ContentPartRecord {
|
public interface IContentQuery<TPart, TRecord> : IContentQuery<TPart> where TPart : IContent where TRecord : ContentPartRecord {
|
||||||
new IContentQuery<TPart, TRecord> ForVersion(VersionOptions options);
|
new IContentQuery<TPart, TRecord> ForVersion(VersionOptions options);
|
||||||
|
|
||||||
IContentQuery<TPart, TRecord> Where(Expression<Func<TRecord, bool>> predicate);
|
IContentQuery<TPart, TRecord> Where(Expression<Func<TRecord, bool>> predicate, params Expression<Func<TRecord, bool>>[] orPredicates);
|
||||||
IContentQuery<TPart, TRecord> OrderBy<TKey>(Expression<Func<TRecord, TKey>> keySelector);
|
IContentQuery<TPart, TRecord> OrderBy<TKey>(Expression<Func<TRecord, TKey>> keySelector);
|
||||||
IContentQuery<TPart, TRecord> OrderByDescending<TKey>(Expression<Func<TRecord, TKey>> keySelector);
|
IContentQuery<TPart, TRecord> OrderByDescending<TKey>(Expression<Func<TRecord, TKey>> keySelector);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user