18
18
namespace NHibernate . Test . CompositeId
19
19
{
20
20
using System . Threading . Tasks ;
21
+ using System . Threading ;
21
22
[ TestFixture ]
22
23
public class CompositeIdFixtureAsync : TestCase
23
24
{
@@ -33,7 +34,7 @@ protected override string[] Mappings
33
34
return new string [ ]
34
35
{
35
36
"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"
37
38
} ;
38
39
}
39
40
}
@@ -76,9 +77,13 @@ public async Task CompositeIdsAsync()
76
77
77
78
Order o = new Order ( c ) ;
78
79
o . OrderDate = DateTime . Today ;
80
+ o . Shipper = new Shipper ( ) { Id = new NullableId ( null , 13 ) } ;
81
+ await ( s . PersistAsync ( o ) ) ;
82
+
79
83
LineItem li = new LineItem ( o , p ) ;
80
84
li . Quantity = 2 ;
81
-
85
+ await ( s . PersistAsync ( li ) ) ;
86
+
82
87
await ( t . CommitAsync ( ) ) ;
83
88
}
84
89
@@ -135,6 +140,19 @@ public async Task CompositeIdsAsync()
135
140
await ( t . CommitAsync ( ) ) ;
136
141
}
137
142
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
+
138
156
using ( s = OpenSession ( ) )
139
157
{
140
158
t = s . BeginTransaction ( ) ;
@@ -303,5 +321,14 @@ public async Task AnyOnCompositeIdAsync()
303
321
await ( s . Query < Order > ( ) . Select ( o => o . LineItems . Any ( ) ) . ToListAsync ( ) ) ;
304
322
}
305
323
}
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
+ }
306
333
}
307
334
}
0 commit comments