Skip to content

Commit

Permalink
Fixed issue in ordering by entity id in sharded HQL queries
Browse files Browse the repository at this point in the history
  • Loading branch information
ggeurts committed Jul 30, 2018
1 parent c1ac558 commit 80d6fde
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/NHibernate.Shards.Test/ShardedIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,27 @@ public void CanOrderWithHql()
}
}

[Test]
public void CanOrderOnIdentifierWithHql()
{
var person1 = new Person { LegalName = new PersonName { FirstName = "John", LastName = "Doe" }, DateOfBirth = new DateTime(1970, 1, 1) };
var person2 = new Person { LegalName = new PersonName { FirstName = "Mary", LastName = "Jane" }, DateOfBirth = new DateTime(1968, 12, 31) };

using (var session = SessionFactory.OpenSession())
{
using (session.BeginTransaction())
{
session.Save(person1);
session.Save(person2);
session.Flush();
session.Clear();

var persistentPersons = session.CreateQuery("from Person p order by p.Id")
.List<Person>();
Assert.That(persistentPersons, Is.Ordered.Ascending.By(nameof(Person.Id)));
}
}
}

[Test]
public void GetFutureResultsMoreThanOnceWithHql()
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate.Shards/NHibernate.Shards.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Description>NHibernate Shards is a framework that adds support for horizontal partitioning to NHibernate Core.</Description>
<Company />
<PackageProjectUrl>https://github.com/darioquintana/NHibernate-Shards</PackageProjectUrl>
<VersionPrefix>5.1.5</VersionPrefix>
<VersionPrefix>5.1.6</VersionPrefix>
<VersionLabel></VersionLabel>
<VersionRevision>4000</VersionRevision>
<VersionSuffix Condition="'$(VersionLabel)' != ''">$(VersionLabel)$(VersionRevision)</VersionSuffix>
Expand Down
4 changes: 3 additions & 1 deletion src/NHibernate.Shards/Query/ShardedQueryExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,9 @@ private void ExtractOrders(IASTNode node)

this.exitOperationBuilder.Orders.Add(
new SortOrder(
o => this.rootClassMetadata.GetPropertyValue(o, propertyPath),
o => propertyPath == this.rootClassMetadata.IdentifierPropertyName
? this.rootClassMetadata.GetIdentifier(o)
: this.rootClassMetadata.GetPropertyValue(o, propertyPath),
isDescending));
}
}
Expand Down

0 comments on commit 80d6fde

Please sign in to comment.