Chapter 29
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 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, enabling you to write LINQ statements that can query the database, pull back the appropriate data, and populate .NET objects that you can work with. In Chapter 30, “The ADO.NET Entity Framework,” 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 ...
Get Professional Visual Studio 2012 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.