From: <ric...@us...> - 2010-11-07 13:37:38
|
Revision: 5260 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5260&view=rev Author: ricbrown Date: 2010-11-07 13:37:31 +0000 (Sun, 07 Nov 2010) Log Message: ----------- QueryOver - added missing overload to allow private property access to order-by Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Criterion/Lambda/QueryOverOrderBuilder.cs trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs trunk/nhibernate/src/NHibernate/IQueryOver.cs trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs Modified: trunk/nhibernate/src/NHibernate/Criterion/Lambda/QueryOverOrderBuilder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/Lambda/QueryOverOrderBuilder.cs 2010-11-02 11:59:09 UTC (rev 5259) +++ trunk/nhibernate/src/NHibernate/Criterion/Lambda/QueryOverOrderBuilder.cs 2010-11-07 13:37:31 UTC (rev 5260) @@ -18,6 +18,9 @@ public QueryOverOrderBuilder(QueryOver<TRoot,TSubType> root, Expression<Func<object>> path, bool isAlias) : base(root, path, isAlias) {} + public QueryOverOrderBuilder(QueryOver<TRoot,TSubType> root, IProjection projection) : base(root, projection) + {} + } public class IQueryOverOrderBuilder<TRoot,TSubType> : QueryOverOrderBuilderBase<IQueryOver<TRoot,TSubType>, TRoot, TSubType> @@ -29,6 +32,9 @@ public IQueryOverOrderBuilder(IQueryOver<TRoot,TSubType> root, Expression<Func<object>> path, bool isAlias) : base(root, path, isAlias) {} + public IQueryOverOrderBuilder(IQueryOver<TRoot,TSubType> root, IProjection projection) : base(root, projection) + {} + } public class QueryOverOrderBuilderBase<TReturn, TRoot, TSubType> where TReturn : IQueryOver<TRoot, TSubType> @@ -37,6 +43,7 @@ protected TReturn root; protected LambdaExpression path; protected bool isAlias; + protected IProjection projection; protected QueryOverOrderBuilderBase(TReturn root, Expression<Func<TSubType, object>> path) { @@ -52,11 +59,25 @@ this.isAlias = isAlias; } + protected QueryOverOrderBuilderBase(TReturn root, IProjection projection) + { + this.root = root; + this.projection = projection; + } + + private void AddOrder(Func<string, Order> orderStringDelegate, Func<IProjection, Order> orderDelegate) + { + if (projection != null) + root.UnderlyingCriteria.AddOrder(orderDelegate(projection)); + else + root.UnderlyingCriteria.AddOrder(ExpressionProcessor.ProcessOrder(path, orderStringDelegate, isAlias)); + } + public TReturn Asc { get { - this.root.UnderlyingCriteria.AddOrder(ExpressionProcessor.ProcessOrder(path, Order.Asc, isAlias)); + AddOrder(Order.Asc, Order.Asc); return this.root; } } @@ -65,7 +86,7 @@ { get { - this.root.UnderlyingCriteria.AddOrder(ExpressionProcessor.ProcessOrder(path, Order.Desc, isAlias)); + AddOrder(Order.Desc, Order.Desc); return this.root; } } Modified: trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2010-11-02 11:59:09 UTC (rev 5259) +++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2010-11-07 13:37:31 UTC (rev 5260) @@ -334,6 +334,11 @@ return new QueryOverOrderBuilder<TRoot,TSubType>(this, path, false); } + public QueryOverOrderBuilder<TRoot,TSubType> OrderBy(IProjection projection) + { + return new QueryOverOrderBuilder<TRoot,TSubType>(this, projection); + } + public QueryOverOrderBuilder<TRoot,TSubType> OrderByAlias(Expression<Func<object>> path) { return new QueryOverOrderBuilder<TRoot,TSubType>(this, path, true); @@ -349,6 +354,11 @@ return new QueryOverOrderBuilder<TRoot,TSubType>(this, path, false); } + public QueryOverOrderBuilder<TRoot,TSubType> ThenBy(IProjection projection) + { + return new QueryOverOrderBuilder<TRoot,TSubType>(this, projection); + } + public QueryOverOrderBuilder<TRoot,TSubType> ThenByAlias(Expression<Func<object>> path) { return new QueryOverOrderBuilder<TRoot,TSubType>(this, path, true); @@ -690,6 +700,9 @@ IQueryOverOrderBuilder<TRoot,TSubType> IQueryOver<TRoot,TSubType>.OrderBy(Expression<Func<object>> path) { return new IQueryOverOrderBuilder<TRoot,TSubType>(this, path, false); } + IQueryOverOrderBuilder<TRoot,TSubType> IQueryOver<TRoot,TSubType>.OrderBy(IProjection projection) + { return new IQueryOverOrderBuilder<TRoot,TSubType>(this, projection); } + IQueryOverOrderBuilder<TRoot,TSubType> IQueryOver<TRoot,TSubType>.OrderByAlias(Expression<Func<object>> path) { return new IQueryOverOrderBuilder<TRoot,TSubType>(this, path, true); } @@ -699,6 +712,9 @@ IQueryOverOrderBuilder<TRoot,TSubType> IQueryOver<TRoot,TSubType>.ThenBy(Expression<Func<object>> path) { return new IQueryOverOrderBuilder<TRoot,TSubType>(this, path, false); } + IQueryOverOrderBuilder<TRoot,TSubType> IQueryOver<TRoot,TSubType>.ThenBy(IProjection projection) + { return new IQueryOverOrderBuilder<TRoot,TSubType>(this, projection); } + IQueryOverOrderBuilder<TRoot,TSubType> IQueryOver<TRoot,TSubType>.ThenByAlias(Expression<Func<object>> path) { return new IQueryOverOrderBuilder<TRoot,TSubType>(this, path, true); } Modified: trunk/nhibernate/src/NHibernate/IQueryOver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/IQueryOver.cs 2010-11-02 11:59:09 UTC (rev 5259) +++ trunk/nhibernate/src/NHibernate/IQueryOver.cs 2010-11-07 13:37:31 UTC (rev 5260) @@ -263,6 +263,11 @@ IQueryOverOrderBuilder<TRoot,TSubType> OrderBy(Expression<Func<object>> path); /// <summary> + /// Order by arbitrary IProjection (e.g., to allow protected member access) + /// </summary> + IQueryOverOrderBuilder<TRoot,TSubType> OrderBy(IProjection projection); + + /// <summary> /// Add order for an aliased projection expressed as a lambda expression /// </summary> /// <param name="path">Lambda expression</param> @@ -284,6 +289,11 @@ IQueryOverOrderBuilder<TRoot,TSubType> ThenBy(Expression<Func<object>> path); /// <summary> + /// Order by arbitrary IProjection (e.g., to allow protected member access) + /// </summary> + IQueryOverOrderBuilder<TRoot,TSubType> ThenBy(IProjection projection); + + /// <summary> /// Add order for an aliased projection expressed as a lambda expression /// </summary> /// <param name="path">Lambda expression</param> Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2010-11-02 11:59:09 UTC (rev 5259) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2010-11-07 13:37:31 UTC (rev 5260) @@ -164,13 +164,15 @@ CreateTestCriteria(typeof(Person)) .SetProjection(Projections.Property("Name")) .Add(Restrictions.Eq("Name", "test name")) - .Add(Restrictions.Not(Restrictions.Eq("Name", "not test name"))); + .Add(Restrictions.Not(Restrictions.Eq("Name", "not test name"))) + .AddOrder(Order.Desc(Projections.Property("Name"))); IQueryOver<Person> actual = CreateTestQueryOver<Person>() .Select(Projections.Property("Name")) .Where(Restrictions.Eq("Name", "test name")) - .And(Restrictions.Not(Restrictions.Eq("Name", "not test name"))); + .And(Restrictions.Not(Restrictions.Eq("Name", "not test name"))) + .OrderBy(Projections.Property("Name")).Desc; AssertCriteriaAreEqual(expected, actual); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |