Chapter 28. Language Integrated Queries (LINQ)

WHAT'S IN THIS CHAPTER?

  • Querying objects with LINQ

  • Writing and querying XML with XLINQ

  • Querying and updating data with LINQ to SQL

Language Integrated Queries (LINQ) was designed to provide a common programming model for querying data. In this chapter you see how you can take some very verbose, imperative code and reduce it to a few declarative lines. This enables you to make your code more descriptive rather than prescriptive; that is, describing what you want to occur, rather than detailing how it should be done.

Although LINQ provides an easy way to filter, sort, and project from an in-memory object graph, it is more common for the data source to be either a database or a file type, such as XML. In this chapter you are introduced to LINQ to XML, which makes working with XML data dramatically simpler than with traditional methods such as using the document object model, XSLT, or XPath. You also learn how to use LINQ to SQL to work with traditional databases, such as SQL Server, allowing you to write LINQ statements that will query the database, pull back the appropriate data, and populate .NET objects that you can work with. In Chapter 29 you are introduced to the ADO.NET Entity Framework for which there is also a LINQ provider. This means that you can combine the power of declarative queries with the fidelity of the Entity Framework to manage your data object life cycle.

LINQ PROVIDERS

One of the key tenets of LINQ is the ability to abstract ...

Get Professional Visual Studio® 2010 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.