Common Code for the Examples

Virtually every example in this chapter will require a DataTable object on which to perform LINQ to DataSet queries. In real production code, you would typically obtain these DataTable objects by querying a database. However, for some of these examples, I present situations where the data conditions in a typical database table will not suffice. For example, I need duplicate records to demonstrate the Distinct method. Rather than jump through hoops trying to manipulate the database to contain the data I may need, I programmatically create a DataTable containing the specific data I desire for each example. This also relieves you of the burden of having a database for testing the majority of these examples.

Since I ...

Get Pro LINQ: Language Integrated Query in C# 2008 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.