194Microsoft Visual Studio 2010: A Beginner’s Guide
options found after clicking the arrow button to expand Database Tools and then selecting Table And Database Designers is “Prevent saving changes that require table
As with so many other features of VS, there are literally dozens of database settings; most are intuitive if you already understand SQL Server. Other options differ, depending on the version of VS you have, and your Options screen might not look the same as Figure
Now that you know how to create databases, tables, and stored procedures, you’ll need to know how to use your database from code. The rest of this chapter shows you how to use LINQ to work with data. First, we’ll look at the basic syntax of LINQ through LINQ to Objects and then follow with working with SQL Server through LINQ to SQL.
Learning Language Integrated Query (LINQ)
LINQ is a set of features built into programming languages, such as C# and VB, for working with data. It’s called Language Integrated Query because the LINQ syntax is part of the language, as opposed to being a separate library. This section will show you the essentials of LINQ with LINQ to Objects, a LINQ provider for querying
The examples in this chapter will use a Console project for simplicity. Later chapters will show you how to display data in desktop and Web applications. If you want to run the code in this chapter, you can create a Console application and type the examples into the Main method, as has been explained in each previous chapter of this book.
Querying Object Collections with LINQ
One way to use LINQ is via LINQ to Objects, which allows you to query collections of objects. You can use LINQ to query any collection that implements the IEnumerable interface. As you may recall, we discussed interfaces in Chapter 4; now you can see one more example of how important interfaces are to .NET development. Listing
a program that uses LINQ to query a collection. The object type is a custom class, named Customer. The Main method creates a generic list of Customer and uses a LINQ query to extract the Customer objects that have a first name that starts with the letter M.