|
From: <ric...@us...> - 2010-07-08 20:48:45
|
Revision: 5002
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5002&view=rev
Author: ricbrown
Date: 2010-07-08 20:48:39 +0000 (Thu, 08 Jul 2010)
Log Message:
-----------
Fix NH-2235 (Corrected type syntax for .SelectList on QueryOver)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs
trunk/nhibernate/src/NHibernate/IQueryOver.cs
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs
Modified: trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2010-07-07 08:39:24 UTC (rev 5001)
+++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2010-07-08 20:48:39 UTC (rev 5002)
@@ -318,9 +318,9 @@
return this;
}
- public QueryOver<TRoot, TSubType> SelectList(Func<QueryOverProjectionBuilder<TSubType>, QueryOverProjectionBuilder<TSubType>> list)
+ public QueryOver<TRoot, TSubType> SelectList(Func<QueryOverProjectionBuilder<TRoot>, QueryOverProjectionBuilder<TRoot>> list)
{
- criteria.SetProjection(list(new QueryOverProjectionBuilder<TSubType>()).ProjectionList);
+ criteria.SetProjection(list(new QueryOverProjectionBuilder<TRoot>()).ProjectionList);
return this;
}
@@ -681,7 +681,7 @@
IQueryOver<TRoot,TSubType> IQueryOver<TRoot,TSubType>.Select(params IProjection[] projections)
{ return Select(projections); }
- IQueryOver<TRoot, TSubType> IQueryOver<TRoot, TSubType>.SelectList(Func<QueryOverProjectionBuilder<TSubType>, QueryOverProjectionBuilder<TSubType>> list)
+ IQueryOver<TRoot, TSubType> IQueryOver<TRoot, TSubType>.SelectList(Func<QueryOverProjectionBuilder<TRoot>, QueryOverProjectionBuilder<TRoot>> list)
{ return SelectList(list); }
IQueryOverOrderBuilder<TRoot,TSubType> IQueryOver<TRoot,TSubType>.OrderBy(Expression<Func<TSubType, object>> path)
Modified: trunk/nhibernate/src/NHibernate/IQueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/IQueryOver.cs 2010-07-07 08:39:24 UTC (rev 5001)
+++ trunk/nhibernate/src/NHibernate/IQueryOver.cs 2010-07-08 20:48:39 UTC (rev 5002)
@@ -246,7 +246,7 @@
/// <summary>
/// Create a list of projections using a projection builder
/// </summary>
- IQueryOver<TRoot, TSubType> SelectList(Func<QueryOverProjectionBuilder<TSubType>, QueryOverProjectionBuilder<TSubType>> list);
+ IQueryOver<TRoot, TSubType> SelectList(Func<QueryOverProjectionBuilder<TRoot>, QueryOverProjectionBuilder<TRoot>> list);
/// <summary>
/// Add order expressed as a lambda expression
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2010-07-07 08:39:24 UTC (rev 5001)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2010-07-08 20:48:39 UTC (rev 5002)
@@ -238,6 +238,56 @@
}
[Test]
+ public void SubCriteriaProjections()
+ {
+ using (ISession s = OpenSession())
+ using (ITransaction t = s.BeginTransaction())
+ {
+ s.Save(new Person() { Name = "Name 1", Age = 33 }
+ .AddChild(new Child() { Nickname = "Name 1.1", Age = 3}));
+
+ t.Commit();
+ }
+
+ using (ISession s = OpenSession())
+ {
+ var simpleProjection =
+ s.QueryOver<Child>()
+ .JoinQueryOver(c => c.Parent)
+ .Where(p => p.Name == "Name 1" && p.Age == 33)
+ .Select(c => c.Nickname, c => c.Age)
+ .List<object[]>()
+ .Select(props => new
+ {
+ Name = (string)props[0],
+ Age = (int)props[1],
+ });
+
+ Assert.That(simpleProjection.Count(), Is.EqualTo(1));
+ Assert.That(simpleProjection.First().Name, Is.EqualTo("Name 1.1"));
+ Assert.That(simpleProjection.First().Age, Is.EqualTo(3));
+
+ var listProjection =
+ s.QueryOver<Child>()
+ .JoinQueryOver(c => c.Parent)
+ .Where(p => p.Name == "Name 1" && p.Age == 33)
+ .SelectList(list => list
+ .Select(c => c.Nickname)
+ .Select(c => c.Age))
+ .List<object[]>()
+ .Select(props => new
+ {
+ Name = (string)props[0],
+ Age = (int)props[1],
+ });
+
+ Assert.That(listProjection.Count(), Is.EqualTo(1));
+ Assert.That(listProjection.First().Name, Is.EqualTo("Name 1.1"));
+ Assert.That(listProjection.First().Age, Is.EqualTo(3));
+ }
+ }
+
+ [Test]
public void SubQuery()
{
using (ISession s = OpenSession())
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|