13.07.2015 Views

C# in Depth

C# in Depth

C# in Depth

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Group<strong>in</strong>gs and cont<strong>in</strong>uations309from defect <strong>in</strong>SampleData.AllDefectsDefect: { ID=1, AssignedTo=Darren ...}Defect: { ID=2, AssignedTo=null ...}Defect: { ID=3, AssignedTo=Tara ...}Defect: { ID=4, AssignedTo=Darren ...}Defect: { ID=5, AssignedTo=Tim ...}Defect: { ID=6, AssignedTo=Darren ...}...where defect.AssignedTo != nullDefect: { ID=1, AssignedTo=Darren ...}Defect: { ID=3, AssignedTo=Tara ...}Defect: { ID=4, AssignedTo=Darren ...}Defect: { ID=5, AssignedTo=Tim ...}Defect: { ID=6, AssignedTo=Darren ...}...group defect by defect.AssignedToKey=DarrenKey=TaraKey=TimDefect: { ID=1, AssignedTo=Darren ...}Defect: { ID=4, AssignedTo=Darren ...}Defect: { ID=6, AssignedTo=Darren ...}...Defect: { ID=3, AssignedTo=Tara ...}Defect: { ID=13, AssignedTo=Tara ...}...Defect: { ID=5, AssignedTo=Tim ...}Defect: { ID=8, AssignedTo=Tim ...}...(Result of query)Figure 11.9 Sequences used when group<strong>in</strong>g defects by assignee. Eachentry of the result has a Key property and is also a sequence of defect entries.When the projection is nontrivial, a slightly more complicated version is used. List<strong>in</strong>g11.18 gives an example of a projection so that we only capture the summary ofeach defect rather than the Defect object itself.List<strong>in</strong>g 11.18Group<strong>in</strong>g defects by assignee—projection reta<strong>in</strong>s just the summaryvar query = from defect <strong>in</strong> SampleData.AllDefectswhere defect.AssignedTo != nullgroup defect.Summary by defect.AssignedTo;foreach (var entry <strong>in</strong> query)Licensed to Rhona Hadida

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!