From 77eedb8f0de21a5b8c8ca5b24a81fda4504ceb6e Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 11 Oct 2011 15:52:26 -0700 Subject: [PATCH] Fixing MatchMode in dynamic queries --HG-- branch : 1.x --- .../ContentManagement/DefaultContentQuery.cs | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/Orchard/ContentManagement/DefaultContentQuery.cs b/src/Orchard/ContentManagement/DefaultContentQuery.cs index 36900be4f..a77a8b7b8 100644 --- a/src/Orchard/ContentManagement/DefaultContentQuery.cs +++ b/src/Orchard/ContentManagement/DefaultContentQuery.cs @@ -297,15 +297,15 @@ namespace Orchard.ContentManagement { } public void Like(string propertyName, string value, MatchMode matchMode, char? escapeChar) { - Criterion = Restrictions.Like(propertyName, value); + Criterion = Restrictions.Like(propertyName, value, ToMatchMode(matchMode), escapeChar); } public void Like(string propertyName, string value, MatchMode matchMode) { - Criterion = Restrictions.Like(propertyName, value); + Criterion = Restrictions.Like(propertyName, value, ToMatchMode(matchMode)); } public void InsensitiveLike(string propertyName, string value, MatchMode matchMode) { - Criterion = Restrictions.InsensitiveLike(propertyName, value); + Criterion = Restrictions.InsensitiveLike(propertyName, value, ToMatchMode(matchMode)); } public void InsensitiveLike(string propertyName, object value) { @@ -386,23 +386,23 @@ namespace Orchard.ContentManagement { public void And(Action lhs, Action rhs) { lhs(this); - ICriterion a = Criterion; + var a = Criterion; rhs(this); - ICriterion b = Criterion; + var b = Criterion; Criterion = Restrictions.And(a, b); } public void Or(Action lhs, Action rhs) { lhs(this); - ICriterion a = Criterion; + var a = Criterion; rhs(this); - ICriterion b = Criterion; + var b = Criterion; Criterion = Restrictions.Or(a, b); } public void Not(Action expression) { expression(this); - ICriterion a = Criterion; + var a = Criterion; Criterion = Restrictions.Not(a); } @@ -434,6 +434,20 @@ namespace Orchard.ContentManagement { Criterion = Restrictions.NaturalId(); } + private static NHibernate.Criterion.MatchMode ToMatchMode(MatchMode matchMode) { + switch(matchMode) { + case MatchMode.Anywhere: + return NHibernate.Criterion.MatchMode.Anywhere; + case MatchMode.End: + return NHibernate.Criterion.MatchMode.End; + case MatchMode.Start: + return NHibernate.Criterion.MatchMode.Start; + case MatchMode.Exact: + return NHibernate.Criterion.MatchMode.Exact; + } + + return NHibernate.Criterion.MatchMode.Anywhere; + } } public class DefaultSortFactory : ISortFactory {