@@ -105,6 +105,31 @@ public class OldAliasedCustomerAddress
105105 public string Country { get ; set ; }
106106 }
107107
108+ [ Alias ( "FooCustomer" ) ]
109+ public class MismatchAliasCustomer
110+ {
111+ [ AutoIncrement ]
112+ public int Id { get ; set ; }
113+ public string Name { get ; set ; }
114+
115+ [ Reference ]
116+ public MismatchAliasAddress PrimaryAddress { get ; set ; }
117+ }
118+
119+ [ Alias ( "BarCustomerAddress" ) ]
120+ public class MismatchAliasAddress
121+ {
122+ [ AutoIncrement ]
123+ public int Id { get ; set ; }
124+ [ Alias ( "BarCustomerId" ) ]
125+ public int MismatchAliasCustomerId { get ; set ; }
126+ public string AddressLine1 { get ; set ; }
127+ public string AddressLine2 { get ; set ; }
128+ public string City { get ; set ; }
129+ public string State { get ; set ; }
130+ public string Country { get ; set ; }
131+ }
132+
108133 public class LoadReferencesTests
109134 : OrmLiteTestBase
110135 {
@@ -122,6 +147,8 @@ public class LoadReferencesTests
122147 db . DropAndCreateTable < AliasedCustomerAddress > ( ) ;
123148 db . DropAndCreateTable < OldAliasedCustomer > ( ) ;
124149 db . DropAndCreateTable < OldAliasedCustomerAddress > ( ) ;
150+ db . DropAndCreateTable < MismatchAliasCustomer > ( ) ;
151+ db . DropAndCreateTable < MismatchAliasAddress > ( ) ;
125152 }
126153
127154 [ TestFixtureTearDown ]
@@ -236,6 +263,36 @@ public void Can_Save_and_Load_Old_Aliased_References()
236263 Assert . That ( dbCustomer . PrimaryAddress , Is . Not . Null ) ;
237264 }
238265
266+ [ Test ]
267+ public void Can_Save_and_Load_MismatchedAlias_References_using_code_conventions ( )
268+ {
269+ var customer = new MismatchAliasCustomer
270+ {
271+ Name = "Customer 1" ,
272+ PrimaryAddress = new MismatchAliasAddress
273+ {
274+ AddressLine1 = "1 Humpty Street" ,
275+ City = "Humpty Doo" ,
276+ State = "Northern Territory" ,
277+ Country = "Australia"
278+ } ,
279+ } ;
280+
281+ db . Save ( customer ) ;
282+
283+ Assert . That ( customer . Id , Is . GreaterThan ( 0 ) ) ;
284+ Assert . That ( customer . PrimaryAddress . MismatchAliasCustomerId , Is . EqualTo ( 0 ) ) ;
285+
286+ db . SaveReferences ( customer , customer . PrimaryAddress ) ;
287+ Assert . That ( customer . PrimaryAddress . MismatchAliasCustomerId , Is . EqualTo ( customer . Id ) ) ;
288+
289+ var dbCustomer = db . LoadSingleById < MismatchAliasCustomer > ( customer . Id ) ;
290+
291+ dbCustomer . PrintDump ( ) ;
292+
293+ Assert . That ( dbCustomer . PrimaryAddress , Is . Not . Null ) ;
294+ }
295+
239296 [ Test ]
240297 public void Can_SaveAllReferences_then_Load_them ( )
241298 {
0 commit comments