Skip to content

Commit db55ffc

Browse files
committed
NH-3428 Unit test to reproduce issue on SQL2005 and above.
This test runs a query which is distinct and ordered paged past page 1.
1 parent 42c0752 commit db55ffc

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
3+
namespace NHibernate.Test.NHSpecificTest.NH3428
4+
{
5+
public class Entity
6+
{
7+
public virtual Guid Id { get; set; }
8+
public virtual string Name { get; set; }
9+
}
10+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using NUnit.Framework;
2+
3+
namespace NHibernate.Test.NHSpecificTest.NH3428
4+
{
5+
using NHibernate.Criterion;
6+
7+
[TestFixture]
8+
public class Fixture : BugTestCase
9+
{
10+
11+
protected override bool AppliesTo(Dialect.Dialect dialect)
12+
{
13+
return dialect is Dialect.MsSql2005Dialect;
14+
}
15+
16+
protected override void OnSetUp()
17+
{
18+
using (ISession session = OpenSession())
19+
using (ITransaction transaction = session.BeginTransaction())
20+
{
21+
var e1 = new Entity { Name = "Bob" };
22+
session.Save(e1);
23+
24+
var e2 = new Entity { Name = "Sally" };
25+
session.Save(e2);
26+
27+
session.Flush();
28+
transaction.Commit();
29+
}
30+
}
31+
32+
protected override void OnTearDown()
33+
{
34+
using (ISession session = OpenSession())
35+
using (ITransaction transaction = session.BeginTransaction())
36+
{
37+
session.Delete("from System.Object");
38+
39+
session.Flush();
40+
transaction.Commit();
41+
}
42+
}
43+
44+
[Test]
45+
public void QueryFailsWhenDistinctOrderedResultIsPagedPastPageOne()
46+
{
47+
using (ISession session = this.OpenSession())
48+
using (session.BeginTransaction())
49+
{
50+
var criteria = session.CreateCriteria<Entity>();
51+
var projectionList = Projections.ProjectionList().Add(Projections.Property("Name"), "Name");
52+
53+
criteria.SetProjection(Projections.Distinct(projectionList));
54+
55+
criteria.SetFirstResult(1).SetMaxResults(1);
56+
criteria.AddOrder(Order.Asc("Name"));
57+
58+
var result = criteria.List();
59+
60+
Assert.AreEqual(1, result.Count);
61+
Assert.AreEqual("Sally", result[0]);
62+
}
63+
}
64+
}
65+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" namespace="NHibernate.Test.NHSpecificTest.NH3428">
3+
4+
<class name="Entity">
5+
<id name="Id" generator="guid.comb" />
6+
<property name="Name" />
7+
</class>
8+
</hibernate-mapping>

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,8 @@
668668
<Compile Include="NHSpecificTest\BagWithLazyExtraAndFilter\Domain.cs" />
669669
<Compile Include="NHSpecificTest\BagWithLazyExtraAndFilter\Fixture.cs" />
670670
<Compile Include="Component\Basic\ComponentWithUniqueConstraintTests.cs" />
671+
<Compile Include="NHSpecificTest\NH3428\Entity.cs" />
672+
<Compile Include="NHSpecificTest\NH3428\Fixture.cs" />
671673
<Compile Include="NHSpecificTest\NH3408\Fixture.cs" />
672674
<Compile Include="NHSpecificTest\NH3408\Model.cs" />
673675
<Compile Include="NHSpecificTest\NH2297\CustomCompositeUserType.cs" />
@@ -2882,6 +2884,7 @@
28822884
<EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" />
28832885
</ItemGroup>
28842886
<ItemGroup>
2887+
<EmbeddedResource Include="NHSpecificTest\NH3428\Mappings.hbm.xml" />
28852888
<EmbeddedResource Include="NHSpecificTest\NH3408\Mappings.hbm.xml" />
28862889
<EmbeddedResource Include="NHSpecificTest\NH2408\Mappings.hbm.xml" />
28872890
<EmbeddedResource Include="NHSpecificTest\NH2297\MappingsNames.hbm.xml" />

0 commit comments

Comments
 (0)