forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62e9513
commit 3d3b092
Showing
4 changed files
with
127 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH3609 | ||
{ | ||
public class Order | ||
{ | ||
public virtual long Id { get; set; } | ||
|
||
public virtual string UniqueId { get; set; } = Guid.NewGuid().ToString(); | ||
|
||
public virtual DateTime CreatedDate { get; set; } | ||
} | ||
|
||
public class LineItem | ||
{ | ||
public virtual long Id { get; set; } | ||
|
||
public virtual Order Order { get; set; } | ||
|
||
public virtual string ItemName { get; set; } | ||
|
||
public virtual decimal Amount { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System; | ||
using System.Linq; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH3609 | ||
{ | ||
[TestFixture] | ||
public class Fixture : BugTestCase | ||
{ | ||
protected override void OnSetUp() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
|
||
var order = new Order | ||
{ | ||
UniqueId = "0ab92479-8a17-4dbc-9bef-ce4344940cec", | ||
CreatedDate = new DateTime(2024, 09, 24) | ||
}; | ||
session.Save(order); | ||
|
||
session.Save(new LineItem { Order = order, ItemName = "Bananas", Amount = 5 }); | ||
|
||
transaction.Commit(); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
|
||
session.CreateQuery("delete from System.Object").ExecuteUpdate(); | ||
|
||
transaction.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void QueryWithAny() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
// This form of query is how we first discovered the issue. This is a simplified reproduction of the | ||
// sort of Linq that we were using in our app. It seems to occur when we force an EXISTS( ... ) subquery. | ||
var validOrders = session.Query<Order>().Where(x => x.CreatedDate > new DateTime(2024, 9, 10)); | ||
var orderCount = session.Query<LineItem>().Count(x => validOrders.Any(y => y == x.Order)); | ||
|
||
Assert.That(orderCount, Is.EqualTo(1)); | ||
} | ||
} | ||
|
||
[Test] | ||
public void QueryWithContains() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
var validOrders = session.Query<Order>().Where(x => x.CreatedDate > new DateTime(2024, 9, 10)); | ||
var orderCount = session.Query<LineItem>().Count(x => validOrders.Contains(x.Order)); | ||
|
||
Assert.That(orderCount, Is.EqualTo(1)); | ||
} | ||
} | ||
|
||
[Test] | ||
public void SimpleQueryForDataWhichWasInsertedViaAdoShouldProvideExpectedResults() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
// This style of equivalent query does not exhibit the problem. This test passes no matter which NH version. | ||
var lineItem = session.Query<LineItem>().FirstOrDefault(x => x.Order.CreatedDate > new DateTime(2024, 9, 10)); | ||
Assert.That(lineItem, Is.Not.Null); | ||
} | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/NHibernate.Test/NHSpecificTest/GH3609/Mappings.hbm.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" | ||
namespace="NHibernate.Test.NHSpecificTest.GH3609"> | ||
|
||
<class name="Order" table="TheOrder"> | ||
<id name="Id" generator="identity" /> | ||
<property name="CreatedDate" /> | ||
<property name="UniqueId" /> | ||
</class> | ||
|
||
<class name="LineItem"> | ||
<id name="Id" generator="identity" /> | ||
<property name="ItemName" /> | ||
<property name="Amount" /> | ||
<many-to-one name="Order" | ||
property-ref="UniqueId" | ||
not-found="ignore" | ||
column="OrderId" /> | ||
</class> | ||
|
||
</hibernate-mapping> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters