Skip to content

Commit fb9c0aa

Browse files
committed
Merge branch 'nh3455' of github.com:jlevitt/nhibernate-core into jlevitt-nh3455
2 parents a26d295 + 3abfaa6 commit fb9c0aa

File tree

7 files changed

+170
-1
lines changed

7 files changed

+170
-1
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
3+
namespace NHibernate.Test.NHSpecificTest.NH3455
4+
{
5+
class Address
6+
{
7+
public virtual Guid Id { get; set; }
8+
public virtual string Street { get; set; }
9+
public virtual string City { get; set; }
10+
public virtual string Zip { get; set; }
11+
public virtual string State { get; set; }
12+
}
13+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
using NHibernate.Criterion;
2+
using NHibernate.Transform;
3+
using NUnit.Framework;
4+
5+
namespace NHibernate.Test.NHSpecificTest.NH3455
6+
{
7+
[TestFixture]
8+
public class Fixture : BugTestCase
9+
{
10+
protected override void OnSetUp()
11+
{
12+
using (var session = OpenSession())
13+
using (var transaction = session.BeginTransaction())
14+
{
15+
var e1 = new Person { Name = "Bob", Age = 31, Weight = 185, Address = new Address
16+
{
17+
City = "Abington",
18+
State = "VA",
19+
Street = "Avenue",
20+
Zip = "11121"
21+
}};
22+
session.Save(e1);
23+
24+
var e2 = new Person
25+
{
26+
Name = "Sally",
27+
Age = 22,
28+
Weight = 122,
29+
Address = new Address
30+
{
31+
City = "Olympia",
32+
State = "WA",
33+
Street = "Broad",
34+
Zip = "99989"
35+
}
36+
};
37+
session.Save(e2);
38+
39+
session.Flush();
40+
transaction.Commit();
41+
}
42+
}
43+
44+
protected override void OnTearDown()
45+
{
46+
using (var session = OpenSession())
47+
using (var transaction = session.BeginTransaction())
48+
{
49+
session.Delete("from System.Object");
50+
51+
session.Flush();
52+
transaction.Commit();
53+
}
54+
}
55+
56+
[Test]
57+
public void OrderBySpecifiedPropertyWithQueryOver()
58+
{
59+
using (var session = OpenSession())
60+
using (session.BeginTransaction())
61+
{
62+
PersonDto dto = null;
63+
var people = session.QueryOver<Person>()
64+
.SelectList(b => b.Select(p => p.Id).WithAlias(() => dto.Id)
65+
.Select(p => p.Name).WithAlias(() => dto.Name)
66+
.Select(p => p.Address).WithAlias(() => dto.Address)
67+
.Select(p => p.Age).WithAlias(() => dto.Age))
68+
.OrderBy(p => p.Age)
69+
.Desc
70+
.TransformUsing(Transformers.AliasToBean<PersonDto>())
71+
.List<PersonDto>();
72+
73+
Assert.That(people.Count, Is.EqualTo(2));
74+
Assert.That(people, Is.Ordered.By("Age").Descending);
75+
}
76+
}
77+
78+
[Test]
79+
public void OrderBySpecifiedPropertyWithCriteria()
80+
{
81+
using (var session = OpenSession())
82+
using (session.BeginTransaction())
83+
{
84+
var selectList = Projections.ProjectionList()
85+
.Add(Projections.Property("Id"), "Id")
86+
.Add(Projections.Property("Name"), "Name")
87+
.Add(Projections.Property("Address"), "Address")
88+
.Add(Projections.Property("Age"), "Age");
89+
var order = new Order("Age", false);
90+
var people = session.CreateCriteria<Person>()
91+
.SetProjection(selectList)
92+
.AddOrder(order)
93+
.SetResultTransformer(Transformers.AliasToBean<PersonDto>())
94+
.List<PersonDto>();
95+
96+
Assert.That(people.Count, Is.EqualTo(2));
97+
Assert.That(people, Is.Ordered.By("Age").Descending);
98+
}
99+
}
100+
}
101+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" namespace="NHibernate.Test.NHSpecificTest.NH3455">
3+
4+
<class name="Person">
5+
<id name="Id" generator="guid.comb" />
6+
<property name="Name" />
7+
<property name="Age" />
8+
<property name="Weight" />
9+
<component name="Address">
10+
<property name="Street" />
11+
<property name="City" />
12+
<property name="Zip" />
13+
<property name="State" />
14+
</component>
15+
</class>
16+
17+
</hibernate-mapping>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
3+
namespace NHibernate.Test.NHSpecificTest.NH3455
4+
{
5+
class Person
6+
{
7+
public virtual Guid Id { get; set; }
8+
public virtual string Name { get; set; }
9+
public virtual int Age { get; set; }
10+
public virtual int Weight { get; set; }
11+
public virtual Address Address { get; set; }
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
3+
namespace NHibernate.Test.NHSpecificTest.NH3455
4+
{
5+
class PersonDto
6+
{
7+
public virtual Guid Id { get; set; }
8+
public virtual string Name { get; set; }
9+
public virtual int Age { get; set; }
10+
public virtual int Weight { get; set; }
11+
public virtual Address Address { get; set; }
12+
}
13+
}

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,10 @@
689689
<Compile Include="Component\Basic\ComponentWithUniqueConstraintTests.cs" />
690690
<Compile Include="NHSpecificTest\NH3620\Fixture.cs" />
691691
<Compile Include="NHSpecificTest\NH3620\TwoBlobs.cs" />
692+
<Compile Include="NHSpecificTest\NH3455\Address.cs" />
693+
<Compile Include="NHSpecificTest\NH3455\PersonDto.cs" />
694+
<Compile Include="NHSpecificTest\NH3455\Person.cs" />
695+
<Compile Include="NHSpecificTest\NH3455\Fixture.cs" />
692696
<Compile Include="NHSpecificTest\NH1082\SynchronizationThatThrowsExceptionAtBeforeTransactionCompletion.cs" />
693697
<Compile Include="NHSpecificTest\NH2756\Fixture.cs" />
694698
<Compile Include="NHSpecificTest\NH2756\Model.cs" />
@@ -3041,6 +3045,7 @@
30413045
<EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" />
30423046
</ItemGroup>
30433047
<ItemGroup>
3048+
<EmbeddedResource Include="NHSpecificTest\NH3455\Mappings.hbm.xml" />
30443049
<EmbeddedResource Include="NHSpecificTest\NH3590\Mappings.hbm.xml" />
30453050
<EmbeddedResource Include="NHSpecificTest\NH3377\Mappings.hbm.xml" />
30463051
<EmbeddedResource Include="NHSpecificTest\NH2865\Mappings.hbm.xml" />

src/NHibernate/Loader/Criteria/CriteriaQueryTranslator.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,14 @@ public string[] GetColumnAliasesUsingProjection(ICriteria subcriteria, string pr
815815
{
816816
//first look for a reference to a projection alias
817817
IProjection projection = rootCriteria.Projection;
818-
string[] projectionColumns = projection == null ? null : projection.GetColumnAliases(propertyName, 0);
818+
string[] projectionColumns = null;
819+
820+
if (projection != null)
821+
{
822+
projectionColumns = projection is IEnhancedProjection
823+
? ((IEnhancedProjection)projection).GetColumnAliases(propertyName, 0, subcriteria, this)
824+
: projection.GetColumnAliases(propertyName, 0);
825+
}
819826

820827
if (projectionColumns == null)
821828
{

0 commit comments

Comments
 (0)