1
1
using System ;
2
+ using System . Collections . Generic ;
2
3
using System . Data ;
3
4
using System . Linq ;
4
5
using NUnit . Framework ;
@@ -154,13 +155,13 @@ private static void InitTables(IDbConnection db)
154
155
db . Insert ( new BarJoin { Id = bar1Id , Name = "Banana" , } ) ;
155
156
db . Insert ( new BarJoin { Id = bar2Id , Name = "Orange" , } ) ;
156
157
157
- _baz1Id = ( int ) db . Insert ( new Baz { Name = "Large" } , true ) ;
158
- _baz2Id = ( int ) db . Insert ( new Baz { Name = "Huge" } , true ) ;
158
+ _baz1Id = ( int ) db . Insert ( new Baz { Name = "Large" } , true ) ;
159
+ _baz2Id = ( int ) db . Insert ( new Baz { Name = "Huge" } , true ) ;
159
160
160
- _fooBar1Id = ( int ) db . Insert ( new FooBar { BarId = bar1Id , } , true ) ;
161
- _fooBar2Id = ( int ) db . Insert ( new FooBar { BarId = bar2Id , } , true ) ;
161
+ _fooBar1Id = ( int ) db . Insert ( new FooBar { BarId = bar1Id , } , true ) ;
162
+ _fooBar2Id = ( int ) db . Insert ( new FooBar { BarId = bar2Id , } , true ) ;
162
163
163
- _fooBarBaz1Id = ( int ) db . Insert ( new FooBarBaz { Amount = 42 , FooBarId = _fooBar1Id , BazId = _baz2Id } , true ) ;
164
+ _fooBarBaz1Id = ( int ) db . Insert ( new FooBarBaz { Amount = 42 , FooBarId = _fooBar1Id , BazId = _baz2Id } , true ) ;
164
165
_fooBarBaz2Id = ( int ) db . Insert ( new FooBarBaz { Amount = 50 , FooBarId = _fooBar1Id , BazId = _baz1Id } , true ) ;
165
166
_fooBarBaz3Id = ( int ) db . Insert ( new FooBarBaz { Amount = 2 , FooBarId = _fooBar2Id , BazId = _baz1Id } , true ) ;
166
167
}
@@ -181,7 +182,7 @@ public void Can_query_contains_on_joined_table_column()
181
182
182
183
q = db . From < FooBar > ( )
183
184
. Join < BarJoin > ( ( dp , p ) => dp . BarId == p . Id )
184
- . Where < FooBar , BarJoin > ( ( f , x ) => x . Name . Contains ( "an" ) ) ;
185
+ . Where < FooBar , BarJoin > ( ( f , x ) => x . Name . Contains ( "an" ) ) ;
185
186
186
187
results = db . Select < JoinResult > ( q ) ;
187
188
Assert . That ( results . Count , Is . EqualTo ( 2 ) ) ;
@@ -252,6 +253,31 @@ public void ComplexJoin_with_SqlExpression()
252
253
}
253
254
}
254
255
256
+ [ Test ]
257
+ public void Can_select_dictionary_from_multiple_tables ( )
258
+ {
259
+ using ( var db = OpenDbConnection ( ) )
260
+ {
261
+ InitTables ( db ) ;
262
+
263
+ var q = db . From < FooBar > ( )
264
+ . Join < BarJoin > ( )
265
+ . Select < FooBar , BarJoin > ( ( f , b ) => new { f . Id , b . Name } ) ;
266
+
267
+ var results = db . Dictionary < int , string > ( q ) ;
268
+
269
+ var sql = db . GetLastSql ( ) ;
270
+ sql . Print ( ) ;
271
+
272
+ results . PrintDump ( ) ;
273
+
274
+ Assert . That ( results , Is . EquivalentTo ( new Dictionary < int , string > {
275
+ { 1 , "Banana" } ,
276
+ { 2 , "Orange" } ,
277
+ } ) ) ;
278
+ }
279
+ }
280
+
255
281
[ Test ]
256
282
public void Can_limit_ComplexJoin_query ( )
257
283
{
0 commit comments