|
From: <ric...@us...> - 2009-07-04 23:30:14
|
Revision: 4574
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4574&view=rev
Author: ricbrown
Date: 2009-07-04 23:30:11 +0000 (Sat, 04 Jul 2009)
Log Message:
-----------
Added ordering to IQueryOver.
Modified Paths:
--------------
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/QueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-07-04 18:58:06 UTC (rev 4573)
+++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-07-04 23:30:11 UTC (rev 4574)
@@ -62,6 +62,26 @@
return Add(expression);
}
+ public QueryOver<T> OrderBy(Expression<Func<T, object>> path, Func<string, Order> orderDelegate)
+ {
+ return AddOrder(path, orderDelegate);
+ }
+
+ public QueryOver<T> OrderBy(Expression<Func<object>> path, Func<string, Order> orderDelegate)
+ {
+ return AddOrder(path, orderDelegate);
+ }
+
+ public QueryOver<T> ThenBy(Expression<Func<T, object>> path, Func<string, Order> orderDelegate)
+ {
+ return AddOrder(path, orderDelegate);
+ }
+
+ public QueryOver<T> ThenBy(Expression<Func<object>> path, Func<string, Order> orderDelegate)
+ {
+ return AddOrder(path, orderDelegate);
+ }
+
public QueryOver<U> JoinQueryOver<U>(Expression<Func<T, U>> path)
{
return new QueryOver<U>(_impl,
@@ -116,7 +136,19 @@
return this;
}
+ private QueryOver<T> AddOrder(Expression<Func<T, object>> path, Func<string, Order> orderDelegate)
+ {
+ _criteria.AddOrder(ExpressionProcessor.ProcessOrder<T>(path, orderDelegate));
+ return this;
+ }
+ private QueryOver<T> AddOrder(Expression<Func<object>> path, Func<string, Order> orderDelegate)
+ {
+ _criteria.AddOrder(ExpressionProcessor.ProcessOrder(path, orderDelegate));
+ return this;
+ }
+
+
IQueryOver<T> IQueryOver<T>.And(Expression<Func<T, bool>> expression)
{ return And(expression); }
@@ -129,6 +161,18 @@
IQueryOver<T> IQueryOver<T>.Where(Expression<Func<bool>> expression)
{ return Where(expression); }
+ IQueryOver<T> IQueryOver<T>.OrderBy(Expression<Func<T, object>> path, Func<string, Order> orderDelegate)
+ { return OrderBy(path, orderDelegate); }
+
+ IQueryOver<T> IQueryOver<T>.OrderBy(Expression<Func<object>> path, Func<string, Order> orderDelegate)
+ { return OrderBy(path, orderDelegate); }
+
+ IQueryOver<T> IQueryOver<T>.ThenBy(Expression<Func<T, object>> path, Func<string, Order> orderDelegate)
+ { return ThenBy(path, orderDelegate); }
+
+ IQueryOver<T> IQueryOver<T>.ThenBy(Expression<Func<object>> path, Func<string, Order> orderDelegate)
+ { return ThenBy(path, orderDelegate); }
+
IQueryOver<U> IQueryOver<T>.JoinQueryOver<U>(Expression<Func<T, U>> path)
{ return JoinQueryOver(path); }
Modified: trunk/nhibernate/src/NHibernate/IQueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-07-04 18:58:06 UTC (rev 4573)
+++ trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-07-04 23:30:11 UTC (rev 4574)
@@ -3,6 +3,8 @@
using System.Collections.Generic;
using System.Linq.Expressions;
+using NHibernate.Criterion;
+
namespace NHibernate
{
@@ -50,6 +52,42 @@
IQueryOver<T> Where(Expression<Func<bool>> expression);
/// <summary>
+ /// Add order expressed as a lambda expression
+ /// </summary>
+ /// <typeparam name="T">Type (same as criteria type)</typeparam>
+ /// <param name="expression">Lambda expression</param>
+ /// <param name="orderDelegate">Order delegate (direction)</param>
+ /// <returns>criteria instance</returns>
+ IQueryOver<T> OrderBy(Expression<Func<T, object>> path, Func<string, Order> orderDelegate);
+
+ /// <summary>
+ /// Add order expressed as a lambda expression
+ /// </summary>
+ /// <typeparam name="T">Type (same as criteria type)</typeparam>
+ /// <param name="expression">Lambda expression</param>
+ /// <param name="orderDelegate">Order delegate (direction)</param>
+ /// <returns>criteria instance</returns>
+ IQueryOver<T> OrderBy(Expression<Func<object>> path, Func<string, Order> orderDelegate);
+
+ /// <summary>
+ /// Add order expressed as a lambda expression
+ /// </summary>
+ /// <typeparam name="T">Type (same as criteria type)</typeparam>
+ /// <param name="expression">Lambda expression</param>
+ /// <param name="orderDelegate">Order delegate (direction)</param>
+ /// <returns>criteria instance</returns>
+ IQueryOver<T> ThenBy(Expression<Func<T, object>> path, Func<string, Order> orderDelegate);
+
+ /// <summary>
+ /// Add order expressed as a lambda expression
+ /// </summary>
+ /// <typeparam name="T">Type (same as criteria type)</typeparam>
+ /// <param name="expression">Lambda expression</param>
+ /// <param name="orderDelegate">Order delegate (direction)</param>
+ /// <returns>criteria instance</returns>
+ IQueryOver<T> ThenBy(Expression<Func<object>> path, Func<string, Order> orderDelegate);
+
+ /// <summary>
/// Creates a new NHibernate.ICriteria<T>, "rooted" at the associated entity
/// </summary>
/// <typeparam name="U">Type of sub-criteria</typeparam>
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-07-04 18:58:06 UTC (rev 4573)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-07-04 23:30:11 UTC (rev 4574)
@@ -177,6 +177,27 @@
AssertCriteriaAreEqual(expected, actual);
}
+ [Test]
+ public void OrderBy()
+ {
+ ICriteria expected =
+ CreateTestCriteria(typeof(Person), "personAlias")
+ .AddOrder(Order.Asc("Name"))
+ .AddOrder(Order.Desc("Age"))
+ .AddOrder(Order.Desc("personAlias.Name"))
+ .AddOrder(Order.Asc("personAlias.Age"));
+
+ Person personAlias = null;
+ IQueryOver<Person> actual =
+ CreateTestQueryOver<Person>(() => personAlias)
+ .OrderBy(p => p.Name, Order.Asc)
+ .ThenBy(p => p.Age, Order.Desc)
+ .ThenBy(() => personAlias.Name, Order.Desc)
+ .ThenBy(() => personAlias.Age, Order.Asc);
+
+ AssertCriteriaAreEqual(expected, actual);
+ }
+
}
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|