Chapter 15

Using LINQ

What you will learn in this chapter:

  • What LINQ is
  • How to query data objects using LINQ
  • The meaning of the var keyword
  • The required LINQ namespaces
  • The advantages of using LINQ to query data objects

wrox.com code downloads for this chapter

You can find the wrox.com code downloads for this chapter at www.wrox.com/remtitle.cgi?isbn=9781118336922 on the Download Code tab. The code in the Chapter15 folder is individually named according to the names throughout the chapter.

SQL is so simple to use; wouldn't it be nice if you could apply its simplicity to data structures other than databases? That's what Microsoft's LINQ is designed to do. LINQ stands for Language INtegrated Query and is a feature that appeared with the debut of Visual Studio 2008.

Using LINQ

Although you can use SQL with relational database objects, LINQ can also query object types where the data source is not a database. You can use LINQ to query an object type, including arrays, class objects, and XML, in addition to relational databases. Visual Studio incorporates the LINQ query engine directly but also has defined an extension definition that enables third-party data sources to tie in to the engine via a translator. Just as SQL queries result in datasets stored in memory, LINQ returns a collection of memory-based objects.

Query Keywords

SQL has specific keywords used in query statements, and LINQ provides a similar set of keywords. Perhaps the easiest way to begin to understand LINQ is to ...

Get Beginning Object-Oriented Programming with C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.