@@ -50,6 +50,14 @@ public class Order
50
50
public decimal Cost { get ; set ; }
51
51
}
52
52
53
+ public class Country
54
+ {
55
+ [ AutoIncrement ]
56
+ public int Id { get ; set ; }
57
+ public string CountryName { get ; set ; }
58
+ public string CountryCode { get ; set ; }
59
+ }
60
+
53
61
/// <summary>
54
62
/// Test POCOs using table aliases and an alias on the foreign key reference
55
63
/// </summary>
@@ -143,6 +151,7 @@ public class LoadReferencesTests
143
151
db . DropAndCreateTable < Order > ( ) ;
144
152
db . DropAndCreateTable < Customer > ( ) ;
145
153
db . DropAndCreateTable < CustomerAddress > ( ) ;
154
+ db . DropAndCreateTable < Country > ( ) ;
146
155
db . DropAndCreateTable < AliasedCustomer > ( ) ;
147
156
db . DropAndCreateTable < AliasedCustomerAddress > ( ) ;
148
157
db . DropAndCreateTable < OldAliasedCustomer > ( ) ;
@@ -366,6 +375,7 @@ public class CustomerJoin
366
375
public string City { get ; set ; }
367
376
public string LineItem { get ; set ; }
368
377
public decimal Cost { get ; set ; }
378
+ public string CountryCode { get ; set ; }
369
379
}
370
380
371
381
[ Test ]
@@ -461,7 +471,7 @@ public void Can_do_joins_with_complex_wheres_using_SqlExpression()
461
471
} ;
462
472
463
473
db . Save ( customer1 , references : true ) ;
464
-
474
+
465
475
var customer2 = new Customer
466
476
{
467
477
Name = "Customer 2" ,
@@ -480,6 +490,10 @@ public void Can_do_joins_with_complex_wheres_using_SqlExpression()
480
490
481
491
db . Save ( customer2 , references : true ) ;
482
492
493
+ db . Insert (
494
+ new Country { CountryName = "Australia" , CountryCode = "AU" } ,
495
+ new Country { CountryName = "USA" , CountryCode = "US" } ) ;
496
+
483
497
var results = db . Select < CustomerJoin , Customer > ( q => q
484
498
. Join < Customer , CustomerAddress > ( )
485
499
. Join < Customer , Order > ( )
@@ -496,12 +510,23 @@ public void Can_do_joins_with_complex_wheres_using_SqlExpression()
496
510
. Where ( c => c . Name == "Customer 2" )
497
511
. And < CustomerAddress , Order > ( ( a , o ) => a . Country == o . LineItem ) ) ;
498
512
513
+ costs = results . ConvertAll ( x => x . Cost ) ;
514
+ Assert . That ( costs , Is . EquivalentTo ( new [ ] { 20m } ) ) ;
515
+
516
+ var countryResults = db . Select < CustomerJoin > ( db . From < Customer > ( )
517
+ . Join < Order > ( ( c , o ) => c . Id == o . CustomerId ) //explicit join condition
518
+ . Join < CustomerAddress > ( ) //implicit join with Customer
519
+ . Join < CustomerAddress , Country > ( ( ca , c ) => ca . Country == c . CountryName )
520
+ . Where ( c => c . Name == "Customer 2" ) //implicit condition with Customer
521
+ . And < CustomerAddress , Order > ( ( a , o ) => a . Country == o . LineItem ) ) ;
522
+
499
523
db . GetLastSql ( ) . Print ( ) ;
500
524
501
- costs = results . ConvertAll ( x => x . Cost ) ;
525
+ costs = countryResults . ConvertAll ( x => x . Cost ) ;
502
526
Assert . That ( costs , Is . EquivalentTo ( new [ ] { 20m } ) ) ;
527
+ Assert . That ( countryResults . ConvertAll ( x => x . CountryCode ) , Is . EquivalentTo ( new [ ] { "US" } ) ) ;
503
528
}
504
-
529
+
505
530
}
506
531
507
532
}
0 commit comments