15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

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

11<br />

language integrated Query<br />

WhaT ’ s in This ChaPTer<br />

➤ Traditional queries across objects using List < T ><br />

➤<br />

➤<br />

➤<br />

➤<br />

Extension methods<br />

LINQ query operators<br />

P a r a l l e l L I N Q<br />

Expression trees<br />

LINQ (Language Integrated Query) integrates query syntax inside the <strong>C#</strong> programming language <strong>and</strong><br />

makes it possible to access different data sources with the same syntax. LINQ makes this possible by<br />

offering an abstraction layer.<br />

This chapter gives you the core foundation of LINQ <strong>and</strong> the language extensions for <strong>C#</strong> that make<br />

the new features possible.<br />

For using LINQ across the database you should read Chapter 31, “ ADO.<strong>NET</strong> Entity<br />

Framework. ” To query XML data, read Chapter 33, “ Manipulating XML, ” after<br />

reading this chapter.<br />

linq oVerVieW<br />

This chapter starts with a simple LINQ query before diving into the full potential of LINQ. The <strong>C#</strong><br />

language offers integrated query language that is converted to method calls. This section shows you<br />

what the conversion looks like so you can use all the possibilities of LINQ.<br />

lists <strong>and</strong> entities<br />

The LINQ queries in this chapter will be done on a collection containing Formula - 1 champions from<br />

1950 to 2008. This data needs to be prepared with entity classes <strong>and</strong> lists.<br />

For the entities, the type Racer is defi ned. Racer defi nes several properties <strong>and</strong> an overloaded<br />

ToString() method to display a racer in a string format. This class implements the interface<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!