Skip to content

Commit b7c9cb5

Browse files
Generate async files
1 parent ec74061 commit b7c9cb5

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/NHibernate.Test/Async/CompositeId/CompositeIdFixture.cs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
namespace NHibernate.Test.CompositeId
1919
{
2020
using System.Threading.Tasks;
21+
using System.Threading;
2122
[TestFixture]
2223
public class CompositeIdFixtureAsync : TestCase
2324
{
@@ -33,7 +34,7 @@ protected override string[] Mappings
3334
return new string[]
3435
{
3536
"CompositeId.Customer.hbm.xml", "CompositeId.Order.hbm.xml", "CompositeId.LineItem.hbm.xml",
36-
"CompositeId.Product.hbm.xml"
37+
"CompositeId.Product.hbm.xml", "CompositeId.Shipper.hbm.xml"
3738
};
3839
}
3940
}
@@ -76,9 +77,13 @@ public async Task CompositeIdsAsync()
7677

7778
Order o = new Order(c);
7879
o.OrderDate = DateTime.Today;
80+
o.Shipper = new Shipper() { Id = new NullableId(null, 13) };
81+
await (s.PersistAsync(o));
82+
7983
LineItem li = new LineItem(o, p);
8084
li.Quantity = 2;
81-
85+
await (s.PersistAsync(li));
86+
8287
await (t.CommitAsync());
8388
}
8489

@@ -135,6 +140,19 @@ public async Task CompositeIdsAsync()
135140
await (t.CommitAsync());
136141
}
137142

143+
using (s = OpenSession())
144+
{
145+
t = s.BeginTransaction();
146+
var noShippersForWarehouse = await (s.Query<Order>()
147+
// NOTE: .Where(x => x.Shipper.Id == new NullableId(null, 13)) improperly renders
148+
// "where (ShipperId = @p1 and WarehouseId = @p2)" with @p1 = NULL (needs to be is null)
149+
// But the effort to fix is pretty high due to how component tuples are managed in linq / hql.
150+
.Where(x => x.Shipper.Id.WarehouseId == 13 && x.Shipper.Id.Id == null)
151+
.ToListAsync());
152+
Assert.AreEqual(1, noShippersForWarehouse.Count);
153+
await (t.CommitAsync());
154+
}
155+
138156
using (s = OpenSession())
139157
{
140158
t = s.BeginTransaction();
@@ -303,5 +321,14 @@ public async Task AnyOnCompositeIdAsync()
303321
await (s.Query<Order>().Select(o => o.LineItems.Any()).ToListAsync());
304322
}
305323
}
324+
325+
public async Task NullCompositeIdAsync(CancellationToken cancellationToken = default(CancellationToken))
326+
{
327+
using (var s = OpenSession())
328+
{
329+
await (s.Query<Order>().Where(o => o.LineItems.Any()).ToListAsync(cancellationToken));
330+
await (s.Query<Order>().Select(o => o.LineItems.Any()).ToListAsync(cancellationToken));
331+
}
332+
}
306333
}
307334
}

src/NHibernate.Test/Async/Linq/JoinTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,17 @@ public async Task OrderLinesWithSelectingCustomerNameInCaseShouldProduceTwoJoins
297297
Assert.That(countJoins, Is.EqualTo(2));
298298
}
299299
}
300+
301+
[Test]
302+
public async Task ShouldConstipateJoinsWhenOnlyComparingCompositeIdPropertiesAsync()
303+
{
304+
using (var spy = new SqlLogSpy())
305+
{
306+
await (db.AnotherEntity.Where(x => x.CompositeIdEntity.Id.TenantId == 3).ToListAsync());
307+
var countJoins = CountJoins(spy);
308+
Assert.That(countJoins, Is.EqualTo(0));
309+
}
310+
}
300311

301312
private static int CountJoins(LogSpy sqlLog)
302313
{

0 commit comments

Comments
 (0)