Skip to content

Commit 2a04948

Browse files
committed
Add tests for nhibernate#3609
1 parent 8945299 commit 2a04948

File tree

4 files changed

+120
-1
lines changed

4 files changed

+120
-1
lines changed
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
3+
namespace NHibernate.Test.NHSpecificTest.GH3609
4+
{
5+
public class Order
6+
{
7+
public virtual long Id { get; set; }
8+
9+
public virtual string UniqueId { get; set; } = Guid.NewGuid().ToString();
10+
11+
public virtual DateTime CreatedDate { get; set; }
12+
}
13+
14+
public class LineItem
15+
{
16+
public virtual long Id { get; set; }
17+
18+
public virtual Order Order { get; set; }
19+
20+
public virtual string ItemName { get; set; }
21+
22+
public virtual decimal Amount { get; set; }
23+
}
24+
}

Diff for: src/NHibernate.Test/NHSpecificTest/GH3609/Fixture.cs

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System;
2+
using System.Linq;
3+
using NUnit.Framework;
4+
5+
namespace NHibernate.Test.NHSpecificTest.GH3609
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 order = new Order
16+
{
17+
UniqueId = "0ab92479-8a17-4dbc-9bef-ce4344940cec",
18+
CreatedDate = new DateTime(2024, 09, 24)
19+
};
20+
session.Save(order);
21+
22+
session.Save(new LineItem { Order = order, ItemName = "Bananas", Amount = 5 });
23+
24+
transaction.Commit();
25+
}
26+
27+
protected override void OnTearDown()
28+
{
29+
using var session = OpenSession();
30+
using var transaction = session.BeginTransaction();
31+
32+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
33+
34+
transaction.Commit();
35+
}
36+
37+
[Test]
38+
public void QueryWithAny()
39+
{
40+
using var session = OpenSession();
41+
using var transaction = session.BeginTransaction();
42+
43+
// This form of query is how we first discovered the issue. This is a simplified reproduction of the
44+
// sort of Linq that we were using in our app. It seems to occur when we force an EXISTS( ... ) subquery.
45+
var validOrders = session.Query<Order>().Where(x => x.CreatedDate > new DateTime(2024, 9, 10));
46+
var orderCount = session.Query<LineItem>().Count(x => validOrders.Any(y => y == x.Order));
47+
48+
Assert.That(orderCount, Is.EqualTo(1));
49+
}
50+
51+
[Test]
52+
public void QueryWithContains()
53+
{
54+
using var session = OpenSession();
55+
using var transaction = session.BeginTransaction();
56+
57+
var validOrders = session.Query<Order>().Where(x => x.CreatedDate > new DateTime(2024, 9, 10));
58+
var orderCount = session.Query<LineItem>().Count(x => validOrders.Contains(x.Order));
59+
60+
Assert.That(orderCount, Is.EqualTo(1));
61+
}
62+
63+
[Test]
64+
public void SimpleQueryForDataWhichWasInsertedViaAdoShouldProvideExpectedResults()
65+
{
66+
using var session = OpenSession();
67+
using var transaction = session.BeginTransaction();
68+
69+
// This style of equivalent query does not exhibit the problem. This test passes no matter which NH version.
70+
var lineItem = session.Query<LineItem>().FirstOrDefault(x => x.Order.CreatedDate > new DateTime(2024, 9, 10));
71+
Assert.That(lineItem, Is.Not.Null);
72+
}
73+
}
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test"
3+
namespace="NHibernate.Test.NHSpecificTest.GH3609">
4+
5+
<class name="Order" table="TheOrder">
6+
<id name="Id" generator="identity" />
7+
<property name="CreatedDate" />
8+
<property name="UniqueId" />
9+
</class>
10+
11+
<class name="LineItem">
12+
<id name="Id" generator="identity" />
13+
<property name="ItemName" />
14+
<property name="Amount" />
15+
<many-to-one name="Order"
16+
property-ref="UniqueId"
17+
not-found="ignore"
18+
column="OrderId" />
19+
</class>
20+
21+
</hibernate-mapping>

Diff for: src/NHibernate/Hql/Ast/ANTLR/Tree/DotNode.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public override void ResolveFirstChild()
163163
string propName = property.Text;
164164
_propertyName = propName;
165165

166-
// If the uresolved property path isn't set yet, just use the property name.
166+
// If the unresolved property path isn't set yet, just use the property name.
167167
if (_propertyPath == null)
168168
{
169169
_propertyPath = propName;

0 commit comments

Comments
 (0)