@@ -64,8 +64,10 @@ public class FullCustomerInfo
6464 {
6565 public int Id { get ; set ; }
6666 public string Name { get ; set ; }
67+ public int CustomerAddressId { get ; set ; }
6768 public string AddressLine1 { get ; set ; }
6869 public string City { get ; set ; }
70+ public int OrderId { get ; set ; }
6971 public string LineItem { get ; set ; }
7072 public decimal Cost { get ; set ; }
7173 public string CountryCode { get ; set ; }
@@ -189,6 +191,8 @@ public void Can_do_joins_with_complex_wheres_using_SqlExpression()
189191
190192 var costs = results . ConvertAll ( x => x . Cost ) ;
191193 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 } ) ) ;
192196
193197 //Same as above using using db.From<Customer>()
194198 results = db . Select < FullCustomerInfo > ( db . From < Customer > ( )
@@ -217,8 +221,6 @@ public void Can_do_joins_with_complex_wheres_using_SqlExpression()
217221 . Where ( c => c . Name == "Customer 2" ) //implicit condition with Customer
218222 . And < CustomerAddress , Order > ( ( a , o ) => a . Country == o . LineItem ) ) ;
219223
220- db . GetLastSql ( ) . Print ( ) ;
221-
222224 costs = countryResults . ConvertAll ( x => x . Cost ) ;
223225 Assert . That ( costs , Is . EquivalentTo ( new [ ] { 20m } ) ) ;
224226 Assert . That ( countryResults . ConvertAll ( x => x . CountryCode ) , Is . EquivalentTo ( new [ ] { "US" } ) ) ;
@@ -362,5 +364,39 @@ public void Can_Join_on_matching_Alias_convention()
362364
363365 Assert . That ( dbAddresses . Count , Is . EqualTo ( 3 ) ) ;
364366 }
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+ }
365401 }
366402}
0 commit comments