File tree Expand file tree Collapse file tree
Shuttle.Core.Data.Tests/QueryMapper Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -42,5 +42,42 @@ select top 1
4242 Assert . AreEqual ( 2 , mappedRows . Count ( ) ) ;
4343 }
4444 }
45+
46+ [ Test ]
47+ public void Should_be_able_to_do_basic_mapping_even_though_columns_are_missing ( )
48+ {
49+ var mapper = new QueryMapper ( new DatabaseGateway ( ) ) ;
50+
51+ var queryRow = RawQuery . Create ( @"
52+ select top 1
53+ Id,
54+ Name as NotMapped,
55+ Age as TheAge
56+ from
57+ BasicMapping
58+ " ) ;
59+
60+ var queryRows = RawQuery . Create ( @"
61+ select
62+ Id,
63+ Name,
64+ Age
65+ from
66+ BasicMapping
67+ " ) ;
68+
69+ using ( GetDatabaseContext ( ) )
70+ {
71+ var item = mapper . MapObject < BasicMapping > ( queryRow ) ;
72+ var items = mapper . MapObjects < BasicMapping > ( queryRows ) ;
73+
74+ Assert . AreEqual ( 2 , items . Count ( ) ) ;
75+
76+ var mappedRow = mapper . MapRow < BasicMapping > ( queryRow ) ;
77+ var mappedRows = mapper . MapRows < BasicMapping > ( queryRows ) ;
78+
79+ Assert . AreEqual ( 2 , mappedRows . Count ( ) ) ;
80+ }
81+ }
4582 }
4683}
Original file line number Diff line number Diff line change @@ -31,15 +31,15 @@ public QueryMapper(IDatabaseGateway databaseGateway)
3131
3232 foreach ( PropertyInfo pi in type . GetProperties ( ) )
3333 {
34- var value = row [ pi . Name ] ;
35-
36- if ( value == null )
37- {
38- continue ;
39- }
40-
4134 try
4235 {
36+ var value = row . Table . Columns . Contains ( pi . Name ) ? row [ pi . Name ] : null ;
37+
38+ if ( value == null )
39+ {
40+ continue ;
41+ }
42+
4343 pi . SetValue ( result , value , null ) ;
4444 }
4545 catch
You can’t perform that action at this time.
0 commit comments