From: <ric...@us...> - 2010-04-27 16:54:50
|
Revision: 4974 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4974&view=rev Author: ricbrown Date: 2010-04-27 16:54:44 +0000 (Tue, 27 Apr 2010) Log Message: ----------- Added RowCountInt64 to IQueryOver. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs trunk/nhibernate/src/NHibernate/IQueryOver.cs trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.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-04-27 16:28:10 UTC (rev 4973) +++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2010-04-27 16:54:44 UTC (rev 4974) @@ -124,6 +124,20 @@ } /// <summary> + /// Clones the QueryOver, clears the orders and paging, and projects the RowCount (Int64) + /// </summary> + /// <returns></returns> + public QueryOver<TRoot,TRoot> ToRowCountInt64Query() + { + return + Clone() + .ClearOrders() + .Skip(0) + .Take(RowSelection.NoValue) + .Select(Projections.RowCountInt64()); + } + + /// <summary> /// Creates an exact clone of the QueryOver /// </summary> public QueryOver<TRoot,TRoot> Clone() @@ -152,9 +166,15 @@ IQueryOver<TRoot,TRoot> IQueryOver<TRoot>.ToRowCountQuery() { return ToRowCountQuery(); } + IQueryOver<TRoot,TRoot> IQueryOver<TRoot>.ToRowCountInt64Query() + { return ToRowCountInt64Query(); } + int IQueryOver<TRoot>.RowCount() { return ToRowCountQuery().SingleOrDefault<int>(); } + long IQueryOver<TRoot>.RowCountInt64() + { return ToRowCountInt64Query().SingleOrDefault<long>(); } + TRoot IQueryOver<TRoot>.SingleOrDefault() { return SingleOrDefault(); } Modified: trunk/nhibernate/src/NHibernate/IQueryOver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/IQueryOver.cs 2010-04-27 16:28:10 UTC (rev 4973) +++ trunk/nhibernate/src/NHibernate/IQueryOver.cs 2010-04-27 16:54:44 UTC (rev 4974) @@ -56,11 +56,22 @@ IQueryOver<TRoot,TRoot> ToRowCountQuery(); /// <summary> - /// Short for ToRowCountQuery().SingleOrDefault() + /// Clones the QueryOver, removes orders and paging, and projects the row-count (Int64) + /// for the query /// </summary> + IQueryOver<TRoot,TRoot> ToRowCountInt64Query(); + + /// <summary> + /// Short for ToRowCountQuery().SingleOrDefault<int>() + /// </summary> int RowCount(); /// <summary> + /// Short for ToRowCountInt64Query().SingleOrDefault<long>() + /// </summary> + long RowCountInt64(); + + /// <summary> /// Convenience method to return a single instance that matches /// the query, or null if the query returns no results. /// </summary> Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2010-04-27 16:28:10 UTC (rev 4973) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2010-04-27 16:54:44 UTC (rev 4974) @@ -278,10 +278,13 @@ IList<Person> results = query.List(); int rowCount = query.RowCount(); + object bigRowCount = query.RowCountInt64(); Assert.That(results.Count, Is.EqualTo(1)); Assert.That(results[0].Name, Is.EqualTo("Name 3")); Assert.That(rowCount, Is.EqualTo(4)); + Assert.That(bigRowCount, Is.TypeOf<long>()); + Assert.That(bigRowCount, Is.EqualTo(4)); } } Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2010-04-27 16:28:10 UTC (rev 4973) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2010-04-27 16:54:44 UTC (rev 4974) @@ -552,6 +552,31 @@ AssertCriteriaAreEqual(expected.UnderlyingCriteria, actual); } + [Test] + public void TransformQueryOverToRowCount64() + { + IQueryOver<Person> expected = + CreateTestQueryOver<Person>() + .Where(p => p.Name == "test") + .JoinQueryOver(p => p.Children) + .Where((Child c) => c.Age == 5) + .Select(Projections.RowCountInt64()); + + 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.ToRowCountInt64Query(); + + 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. |