O'Reilly logo

Professional C# 4 and .NET 4 by Morgan Skinner, Karli Watson, Jay Glynn, Bill Evjen, Christian Nagel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 11. Language Integrated Query

WHAT'S IN THIS CHAPTER?

  • Traditional queries across objects using List<T>

  • Extension methods

  • LINQ query operators

  • Parallel LINQ

  • Expression trees

LINQ (Language Integrated Query) integrates query syntax inside the C# programming language and makes it possible to access different data sources with the same syntax. LINQ makes this possible by offering an abstraction layer.

This chapter gives you the core foundation of LINQ and the language extensions for C# that make the new features possible.

Note

For using LINQ across the database you should read Chapter 31, "ADO.NET Entity Framework." To query XML data, read Chapter 33, "Manipulating XML," after reading this chapter.

LINQ OVERVIEW

This chapter starts with a simple LINQ query before diving into the full potential of LINQ. The C# language offers integrated query language that is converted to method calls. This section shows you what the conversion looks like so you can use all the possibilities of LINQ.

Lists and Entities

The LINQ queries in this chapter will be done on a collection containing Formula-1 champions from 1950 to 2008. This data needs to be prepared with entity classes and lists.

For the entities, the type Racer is defined. Racer defines several properties and an overloaded ToString() method to display a racer in a string format. This class implements the interface IFormattable to support different variants of format strings, and the interface IComparable<Racer>, which can be used to sort a list ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required