diff --git a/src/NHibernate.Shards.Test/ShardedIntegrationTests.cs b/src/NHibernate.Shards.Test/ShardedIntegrationTests.cs index 2678b78..34f19a5 100644 --- a/src/NHibernate.Shards.Test/ShardedIntegrationTests.cs +++ b/src/NHibernate.Shards.Test/ShardedIntegrationTests.cs @@ -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(); + Assert.That(persistentPersons, Is.Ordered.Ascending.By(nameof(Person.Id))); + } + } + } [Test] public void GetFutureResultsMoreThanOnceWithHql() diff --git a/src/NHibernate.Shards/NHibernate.Shards.csproj b/src/NHibernate.Shards/NHibernate.Shards.csproj index 5e495c7..0b99fe7 100644 --- a/src/NHibernate.Shards/NHibernate.Shards.csproj +++ b/src/NHibernate.Shards/NHibernate.Shards.csproj @@ -7,7 +7,7 @@ NHibernate Shards is a framework that adds support for horizontal partitioning to NHibernate Core. https://github.com/darioquintana/NHibernate-Shards - 5.1.5 + 5.1.6 4000 $(VersionLabel)$(VersionRevision) diff --git a/src/NHibernate.Shards/Query/ShardedQueryExpression.cs b/src/NHibernate.Shards/Query/ShardedQueryExpression.cs index 696a1c9..5412f6d 100644 --- a/src/NHibernate.Shards/Query/ShardedQueryExpression.cs +++ b/src/NHibernate.Shards/Query/ShardedQueryExpression.cs @@ -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)); } }