@@ -125,14 +125,13 @@ private static void QueryAllDocuments(string collectionLink)
125
125
var families =
126
126
from f in client . CreateDocumentQuery < Family > ( collectionLink , DefaultOptions )
127
127
select f ;
128
-
129
- var families = query . ToList ( ) ;
130
- Assert ( "Expected two families" , families . Count == 2 ) ;
128
+
129
+ Assert ( "Expected two families" , families . ToList ( ) . Count == 2 ) ;
131
130
132
131
// LINQ Lambda
133
132
families = client . CreateDocumentQuery < Family > ( collectionLink , DefaultOptions ) ;
134
133
Assert ( "Expected two families" , families . ToList ( ) . Count == 2 ) ;
135
-
134
+
136
135
// SQL
137
136
families = client . CreateDocumentQuery < Family > ( collectionLink , "SELECT * FROM Families" , DefaultOptions ) ;
138
137
Assert ( "Expected two families" , families . ToList ( ) . Count == 2 ) ;
@@ -214,8 +213,7 @@ from f in client.CreateDocumentQuery<Family>(collectionLink, DefaultOptions)
214
213
. Where ( f => f . Id == "AndersenFamily" || f . Address . City == "NY" )
215
214
. Select ( f => new { Name = f . LastName , City = f . Address . City } ) ;
216
215
217
- items = query . ToList ( ) ;
218
- foreach ( var item in items )
216
+ foreach ( var item in query )
219
217
{
220
218
Console . WriteLine ( "The {0} family live in {1}" , item . Name , item . City ) ;
221
219
}
@@ -239,16 +237,15 @@ private static void QueryWithAndFilter(string collectionLink)
239
237
where f . Id == "AndersenFamily" && f . Address . City == "Seattle"
240
238
select f ;
241
239
242
- var families = query . ToList ( ) ;
243
- Assert ( "Expected only 1 family" , families . Count == 1 ) ;
240
+ Assert ( "Expected only 1 family" , families . ToList ( ) . Count == 1 ) ;
244
241
245
242
// LINQ Lambda -- Id == "value" AND City == "value"
246
243
families = client . CreateDocumentQuery < Family > ( collectionLink , DefaultOptions )
247
244
. Where ( f => f . Id == "AndersenFamily" && f . Address . City == "Seattle" ) ;
248
245
Assert ( "Expected only 1 family" , families . ToList ( ) . Count == 1 ) ;
249
246
250
247
// SQL -- Id == "value" AND City == "value"
251
- query = client . CreateDocumentQuery < Family > (
248
+ families = client . CreateDocumentQuery < Family > (
252
249
collectionLink ,
253
250
"SELECT * FROM Families f WHERE f.id='AndersenFamily' AND f.Address.City='Seattle'" ,
254
251
DefaultOptions ) ;
@@ -263,8 +260,7 @@ from f in client.CreateDocumentQuery<Family>(collectionLink, DefaultOptions)
263
260
where f . Id == "AndersenFamily"
264
261
select f ;
265
262
266
- var families = query . ToList ( ) ;
267
- Assert ( "Expected only 1 family" , families . Count == 1 ) ;
263
+ Assert ( "Expected only 1 family" , families . ToList ( ) . Count == 1 ) ;
268
264
269
265
// LINQ Lambda -- Id == "value"
270
266
families = client . CreateDocumentQuery < Family > ( collectionLink , DefaultOptions ) . Where ( f => f . Id == "AndersenFamily" ) ;
@@ -282,31 +278,32 @@ private static void QueryWithInequality(string collectionLink)
282
278
{
283
279
// Simple query with a single property inequality comparison
284
280
// LINQ Query
285
- var families = from f in client . CreateDocumentQuery < Family > ( collectionLink , DefaultOptions )
281
+ var query = from f in client . CreateDocumentQuery < Family > ( collectionLink , DefaultOptions )
286
282
where f . Id != "AndersenFamily"
287
283
select f ;
288
284
289
285
var families = query . ToList ( ) ;
290
286
Assert ( "Expected only 1 family" , families . Count == 1 ) ;
291
287
292
288
// LINQ Lambda
293
- families = client . CreateDocumentQuery < Family > ( collectionLink , DefaultOptions )
289
+ query = client . CreateDocumentQuery < Family > ( collectionLink , DefaultOptions )
294
290
. Where ( f => f . Id != "AndersenFamily" ) ;
295
291
296
292
families = query . ToList ( ) ;
297
293
Assert ( "Expected only 1 family" , families . Count == 1 ) ;
298
294
299
295
300
296
// SQL - in SQL you can use <> interchangably with != for "not equals"
301
- families = client . CreateDocumentQuery < Family > (
297
+ query = client . CreateDocumentQuery < Family > (
302
298
collectionLink ,
303
299
"SELECT * FROM Families f WHERE f.id <> 'AndersenFamily'" ,
304
300
DefaultOptions ) ;
305
301
302
+ families = query . ToList ( ) ;
306
303
Assert ( "Expected only 1 family" , families . ToList ( ) . Count == 1 ) ;
307
304
308
305
//combine equality and inequality
309
- families =
306
+ query =
310
307
from f in client . CreateDocumentQuery < Family > ( collectionLink , DefaultOptions )
311
308
where f . Id == "Wakefield" && f . Address . City != "NY"
312
309
select f ;
@@ -330,23 +327,20 @@ private static void QueryWithRangeOperatorsOnNumbers(string collectionLink)
330
327
where f . Children [ 0 ] . Grade > 5
331
328
select f ;
332
329
333
- var families = query . ToList ( ) ;
334
- Assert ( "Expected only 1 family" , families . Count == 1 ) ;
330
+ Assert ( "Expected only 1 family" , families . ToList ( ) . Count == 1 ) ;
335
331
336
332
// LINQ Lambda
337
333
families = client . CreateDocumentQuery < Family > ( collectionLink , DefaultOptions )
338
334
. Where ( f => f . Children [ 0 ] . Grade > 5 ) ;
339
335
340
- families = query . ToList ( ) ;
341
- Assert ( "Expected only 1 family" , families . Count == 1 ) ;
336
+ Assert ( "Expected only 1 family" , families . ToList ( ) . Count == 1 ) ;
342
337
343
338
// SQL
344
339
families = client . CreateDocumentQuery < Family > ( collectionLink ,
345
340
"SELECT * FROM Families f WHERE f.Children[0].Grade > 5" ,
346
341
DefaultOptions ) ;
347
342
348
- families = query . ToList ( ) ;
349
- Assert ( "Expected only 1 family" , families . Count == 1 ) ;
343
+ Assert ( "Expected only 1 family" , families . ToList ( ) . Count == 1 ) ;
350
344
}
351
345
352
346
@@ -362,7 +356,7 @@ private static void QueryWithOrderBy(string collectionLink)
362
356
private static void QueryWithRangeOperatorsOnStrings ( string collectionLink )
363
357
{
364
358
// SQL Query (can't do this in LINQ)
365
- var query = client . CreateDocumentQuery < Family > (
359
+ var families = client . CreateDocumentQuery < Family > (
366
360
collectionLink ,
367
361
"SELECT * FROM Families f WHERE f.Address.State > 'NY'" ,
368
362
new FeedOptions { EnableScanInQuery = true , EnableCrossPartitionQuery = true } ) ;
@@ -405,25 +399,22 @@ private static void QueryWithOrderByStrings(string collectionLink)
405
399
orderby f . Address . State descending
406
400
select f ;
407
401
408
- var families = query . ToList ( ) ;
409
- Assert ( "Expected only 1 family" , families . Count == 1 ) ;
402
+ Assert ( "Expected only 1 family" , familiesLinqQuery . ToList ( ) . Count == 1 ) ;
410
403
411
404
// LINQ Lambda
412
405
familiesLinqQuery = client . CreateDocumentQuery < Family > ( collectionLink , DefaultOptions )
413
406
. Where ( f => f . LastName == "Andersen" )
414
407
. OrderByDescending ( f => f . Address . State ) ;
415
408
416
- families = query . ToList ( ) ;
417
- Assert ( "Expected only 1 family" , families . Count == 1 ) ;
409
+ Assert ( "Expected only 1 family" , familiesLinqQuery . ToList ( ) . Count == 1 ) ;
418
410
419
411
// SQL
420
412
var familiesSqlQuery = client . CreateDocumentQuery < Family > (
421
413
collectionLink ,
422
414
"SELECT * FROM Families f WHERE f.LastName = 'Andersen' ORDER BY f.Address.State DESC" ,
423
415
DefaultOptions ) ;
424
416
425
- families = q . ToList ( ) ;
426
- Assert ( "Expected only 1 family" , families . Count == 1 ) ;
417
+ Assert ( "Expected only 1 family" , familiesSqlQuery . ToList ( ) . Count == 1 ) ;
427
418
}
428
419
429
420
private static void QueryWithSubdocuments ( string collectionLink )
@@ -438,8 +429,7 @@ private static void QueryWithSubdocuments(string collectionLink)
438
429
"SELECT c FROM c IN f.Children" ,
439
430
DefaultOptions ) . ToList ( ) ;
440
431
441
- var children = query . ToList ( ) ;
442
- foreach ( var child in children )
432
+ foreach ( var child in childrenSqlQuery )
443
433
{
444
434
Console . WriteLine ( JsonConvert . SerializeObject ( child ) ) ;
445
435
}
@@ -449,8 +439,7 @@ private static void QueryWithSubdocuments(string collectionLink)
449
439
. SelectMany ( family => family . Children
450
440
. Select ( c => c ) ) ;
451
441
452
- children = query . ToList ( ) ;
453
- foreach ( var child in children )
442
+ foreach ( var child in childrenLinqQuery )
454
443
{
455
444
Console . WriteLine ( JsonConvert . SerializeObject ( child ) ) ;
456
445
}
@@ -489,7 +478,7 @@ private static void QueryWithTwoJoinsAndFilter(string collectionLink)
489
478
}
490
479
491
480
// LINQ
492
- familiesChildrenAndPets = client . CreateDocumentQuery < Family > ( collectionLink , DefaultOptions )
481
+ var familiesChildrenAndPets = client . CreateDocumentQuery < Family > ( collectionLink , DefaultOptions )
493
482
. SelectMany ( family => family . Children
494
483
. SelectMany ( child => child . Pets
495
484
. Where ( pet => pet . GivenName == "Fluffy" )
@@ -501,10 +490,9 @@ private static void QueryWithTwoJoinsAndFilter(string collectionLink)
501
490
}
502
491
) ) ) ;
503
492
504
- items = query . ToList ( ) ;
505
- foreach ( var item in items )
493
+ foreach ( var pet in familiesChildrenAndPets )
506
494
{
507
- Console . WriteLine ( item ) ;
495
+ Console . WriteLine ( pet ) ;
508
496
}
509
497
}
510
498
@@ -519,8 +507,7 @@ private static void QueryWithTwoJoins(string collectionLink)
519
507
"JOIN p IN c.Pets " ,
520
508
DefaultOptions ) ;
521
509
522
- var items = query . ToList ( ) ;
523
- foreach ( var item in items )
510
+ foreach ( var item in familiesChildrenAndPets )
524
511
{
525
512
Console . WriteLine ( item ) ;
526
513
}
@@ -536,9 +523,8 @@ private static void QueryWithTwoJoins(string collectionLink)
536
523
pet = pet . GivenName
537
524
}
538
525
) ) ) ;
539
-
540
- items = query . ToList ( ) ;
541
- foreach ( var item in items )
526
+
527
+ foreach ( var item in familiesChildrenAndPets )
542
528
{
543
529
Console . WriteLine ( item ) ;
544
530
}
@@ -553,19 +539,17 @@ private static void QueryWithSingleJoin(string collectionLink)
553
539
"FROM Families f " +
554
540
"JOIN c IN f.Children" , DefaultOptions ) ;
555
541
556
- var items = query . ToList ( ) ;
557
- foreach ( var item in items )
542
+ foreach ( var item in query )
558
543
{
559
544
Console . WriteLine ( JsonConvert . SerializeObject ( item ) ) ;
560
545
}
561
546
562
547
// LINQ
563
- familiesAndChildren = client . CreateDocumentQuery < Family > ( collectionLink , DefaultOptions )
548
+ var familiesAndChildren = client . CreateDocumentQuery < Family > ( collectionLink , DefaultOptions )
564
549
. SelectMany ( family => family . Children
565
550
. Select ( c => family . Id ) ) ;
566
551
567
- items = query . ToList ( ) ;
568
- foreach ( var item in items )
552
+ foreach ( var item in familiesAndChildren )
569
553
{
570
554
Console . WriteLine ( JsonConvert . SerializeObject ( item ) ) ;
571
555
}
0 commit comments