@@ -64,8 +64,10 @@ public class FullCustomerInfo
64
64
{
65
65
public int Id { get ; set ; }
66
66
public string Name { get ; set ; }
67
+ public int CustomerAddressId { get ; set ; }
67
68
public string AddressLine1 { get ; set ; }
68
69
public string City { get ; set ; }
70
+ public int OrderId { get ; set ; }
69
71
public string LineItem { get ; set ; }
70
72
public decimal Cost { get ; set ; }
71
73
public string CountryCode { get ; set ; }
@@ -189,6 +191,8 @@ public void Can_do_joins_with_complex_wheres_using_SqlExpression()
189
191
190
192
var costs = results . ConvertAll ( x => x . Cost ) ;
191
193
Assert . That ( costs , Is . EquivalentTo ( new [ ] { 1.99m , 1.49m , 9.99m } ) ) ;
194
+ var orderIds = results . ConvertAll ( x => x . OrderId ) ;
195
+ Assert . That ( orderIds , Is . EquivalentTo ( new [ ] { 1 , 3 , 5 } ) ) ;
192
196
193
197
//Same as above using using db.From<Customer>()
194
198
results = db . Select < FullCustomerInfo > ( db . From < Customer > ( )
@@ -217,8 +221,6 @@ public void Can_do_joins_with_complex_wheres_using_SqlExpression()
217
221
. Where ( c => c . Name == "Customer 2" ) //implicit condition with Customer
218
222
. And < CustomerAddress , Order > ( ( a , o ) => a . Country == o . LineItem ) ) ;
219
223
220
- db . GetLastSql ( ) . Print ( ) ;
221
-
222
224
costs = countryResults . ConvertAll ( x => x . Cost ) ;
223
225
Assert . That ( costs , Is . EquivalentTo ( new [ ] { 20m } ) ) ;
224
226
Assert . That ( countryResults . ConvertAll ( x => x . CountryCode ) , Is . EquivalentTo ( new [ ] { "US" } ) ) ;
@@ -362,5 +364,39 @@ public void Can_Join_on_matching_Alias_convention()
362
364
363
365
Assert . That ( dbAddresses . Count , Is . EqualTo ( 3 ) ) ;
364
366
}
367
+
368
+ [ Test ]
369
+ public void Does_populate_PrimaryKey_ids_based_on_property_convention ( )
370
+ {
371
+ // Reset auto ids
372
+ db . DropAndCreateTable < Order > ( ) ;
373
+ db . DropAndCreateTable < CustomerAddress > ( ) ;
374
+ db . DropAndCreateTable < Customer > ( ) ;
375
+
376
+ AddCustomerWithOrders ( ) ;
377
+
378
+ var results = db . Select < FullCustomerInfo , Customer > ( q => q
379
+ . Join < Customer , CustomerAddress > ( )
380
+ . Join < Customer , Order > ( ) ) ;
381
+
382
+ var addressIds = results . ConvertAll ( x => x . CustomerAddressId ) ;
383
+ Assert . That ( addressIds , Is . EquivalentTo ( new [ ] { 1 , 1 } ) ) ;
384
+
385
+ var orderIds = results . ConvertAll ( x => x . OrderId ) ;
386
+ Assert . That ( orderIds , Is . EquivalentTo ( new [ ] { 1 , 2 } ) ) ;
387
+
388
+ var expr = db . From < Customer > ( )
389
+ . Join < Customer , CustomerAddress > ( )
390
+ . Join < Customer , Order > ( )
391
+ . Where < Order > ( o => o . Cost > 2 ) ;
392
+
393
+ results = db . Select < FullCustomerInfo > ( expr ) ;
394
+
395
+ addressIds = results . ConvertAll ( x => x . CustomerAddressId ) ;
396
+ Assert . That ( addressIds , Is . EquivalentTo ( new [ ] { 1 } ) ) ;
397
+
398
+ orderIds = results . ConvertAll ( x => x . OrderId ) ;
399
+ Assert . That ( orderIds , Is . EquivalentTo ( new [ ] { 2 } ) ) ;
400
+ }
365
401
}
366
402
}
0 commit comments