03.01.2015 Views

C# 5.0 Programmer's Reference

Visual Studio 2013 C# 5.0 Programmer's Reference

Visual Studio 2013 C# 5.0 Programmer's Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

J<br />

LINQ<br />

This appendix provides syntax summaries for the most useful LINQ methods. For more<br />

detailed information, see Chapter 8, “LINQ.”<br />

Basic LINQ Query Syntax<br />

The following text shows the typical syntax for a LINQ query.<br />

from ... where ... orderby ... select ...<br />

The following sections describe these four standard clauses. The sections after those describe<br />

some of the other most useful LINQ clauses.<br />

from<br />

The from clause tells where the data comes from and defines the name by which it is known<br />

within the LINQ query.<br />

Examples:<br />

from queryVariable in dataSource<br />

var customerQuery =<br />

from person in customers<br />

select person;<br />

var scoresQuery =<br />

from student in students<br />

from score in testScores<br />

where student.StudentId == score.StudentId<br />

select new {student, score};<br />

Usually, if you select data from multiple sources, you will want to use a where clause to join<br />

the results from the sources.<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!