1818namespace 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}
0 commit comments