C#: LINQ – Query

Please see my other LINQ articles.

Performing a simple query.

Using Microsoft’s new elegant syntax or subset of the .NET framework that looks like it might be replacing ADO.NET, I will illustrate how to perform a simple query.
This new syntax is much less bulky than executing the same query using ADO.NET commands.
First, I’ll begin by creating a class to represent test Order records.

1-linq-query

With my new class ready, I’ll instantiate a series of fake orders similar to what you might see in a live system.
Now that I’ve got a collection of test orders, I’ll perform a simple query using Linq to return all orders.

3-linq-query

The previous query populated a Linq object with all orders from my test data source.
I will now run a simple application to iterate through the collection while displaying each order’s data.

4-linq-query

As you can see, all test orders have written to the screen.

5-linq-query

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s