|
From: <ric...@us...> - 2010-03-07 10:16:15
|
Revision: 4955
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4955&view=rev
Author: ricbrown
Date: 2010-03-07 10:16:09 +0000 (Sun, 07 Mar 2010)
Log Message:
-----------
Added ToRowCountQuery method to interface to allow access to the query without performing execution.
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 2010-03-07 09:47:45 UTC (rev 4954)
+++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2010-03-07 10:16:09 UTC (rev 4955)
@@ -147,6 +147,9 @@
IList<U> IQueryOver<TRoot>.List<U>()
{ return List<U>(); }
+ IQueryOver<TRoot,TRoot> IQueryOver<TRoot>.ToRowCountQuery()
+ { return ToRowCountQuery(); }
+
int IQueryOver<TRoot>.RowCount()
{ return ToRowCountQuery().SingleOrDefault<int>(); }
Modified: trunk/nhibernate/src/NHibernate/IQueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/IQueryOver.cs 2010-03-07 09:47:45 UTC (rev 4954)
+++ trunk/nhibernate/src/NHibernate/IQueryOver.cs 2010-03-07 10:16:09 UTC (rev 4955)
@@ -42,9 +42,14 @@
IList<U> List<U>();
/// <summary>
- /// Clones the QueryOver, removes orders and paging, projects the row-count
- /// for the query and returns the Single() result
+ /// Clones the QueryOver, removes orders and paging, and projects the row-count
+ /// for the query
/// </summary>
+ IQueryOver<TRoot,TRoot> ToRowCountQuery();
+
+ /// <summary>
+ /// Short for ToRowCountQuery().SingleOrDefault()
+ /// </summary>
int RowCount();
/// <summary>
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2010-03-07 09:47:45 UTC (rev 4954)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2010-03-07 10:16:09 UTC (rev 4955)
@@ -527,6 +527,31 @@
AssertCriteriaAreEqual(expected.UnderlyingCriteria, actual.UnderlyingCriteria);
}
+ [Test]
+ public void TransformQueryOverToRowCount()
+ {
+ IQueryOver<Person> expected =
+ CreateTestQueryOver<Person>()
+ .Where(p => p.Name == "test")
+ .JoinQueryOver(p => p.Children)
+ .Where((Child c) => c.Age == 5)
+ .Select(Projections.RowCount());
+
+ IQueryOver<Person> actual =
+ CreateTestQueryOver<Person>()
+ .Where(p => p.Name == "test")
+ .JoinQueryOver(p => p.Children)
+ .Where((Child c) => c.Age == 5)
+ .OrderBy(c => c.Age).Asc
+ .Skip(20)
+ .Take(10);
+
+ expected = expected.Clone();
+ actual = actual.ToRowCountQuery();
+
+ AssertCriteriaAreEqual(expected.UnderlyingCriteria, 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.
|