Writing LINQ Queries with the Entity Framework
Introduction
The problem with data is that it exists in many formats and until now has required that developers learn multiple competing technologies. If you want to query Active Directory, for example, you have to learn Lightweight Directory Access Protocol (LDAP). If you want to query a database, you need to learn SQL. If you want to manage XML data, you have to learn XPath (or XQuery). These are completely different technologies, and mastering each is no trivial task.
LINQ is an integrated query technology that enables you to use the same technology, LINQ, to query any of these other technologies—including custom objects—using the same query grammar and language features. And it doesn't matter where the data lives.
LINQ to SQL is already available with .NET 3.5. LINQ to SQL lets you query against SQL entities, while the .NET Framework handles the ADO.NET plumbing. LINQ to Entities will be available with Visual Studio 2008 SP1 sometime later in 2008. LINQ to Entities is built on top of LINQ and ADO.NET 3.0. Whereas LINQ to SQL treats tables as entities, LINQ to Entities lets you define new entities that may map to multiple tables, querying and modifying the entities in an object-oriented way using LINQ. You don't have to define the entities manually. You don't have to write a stitch of ADO.NET code or queries. All you do is program against the entities you choose.
This article provides an introduction to LINQ to entities, demonstrating reading and modifying data as well as the new SPAN capability that gets related data in one round trip.
You'll need Visual Studio 2008, and you'll have to download the LINQ to Entities ADO.NET Framework beta software from Microsoft.com. As always, consider backing up your system or using a virtual PC instance any time you use beta software.