Chapter 15. LINQ: Get control of your data

image with no caption

It’s a data-driven world...you better know how to live in it.

Gone are the days when you could program for days, even weeks, without dealing with loads of data. But today, everything is about data. In fact, you’ll often have to work with data from more than one place...and in more than one format. Databases, XML, collections from other programs...it’s all part of the job of a good C# programmer. And that’s where LINQ comes in. LINQ not only lets you query data in a simple, intuitive way, but it lets you group data, and merge data from different data sources.

An easy project...

Objectville Paper Company wants to do a cross-promotion with Starbuzz Coffee. Starbuzz has a frequent-customer program where they keep track of which customers buy which drink and how often they buy it. Objectville Paper wants to figure out which of their customers are also Starbuzz regulars and send them a free mug and a coupon for their favorite coffee drink...and it’s up to you to combine the data and generate the list of customers to send mugs and coupons to.

image with no caption

...but the data’s all over the place

Starbuzz keeps all their data in classes, grouped together in a big List. But the Objectville data is in a database (from way back in Chapter 1). We want to find any Starbuzz customers ...

Get Head First C#, 2nd Edition 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.