Introducing the Entity Framework and LINQ
Discover Microsoft's two new technologies that form the Dynamic Development pillar of SQL Server 2008.
The Entity Framework (EF) and Language Integrated Query (LINQ) are two new technologies in Visual Studio 2008 that form one of the Pillars of SQL Server 2008 (formerly "Katmai"): Dynamic Development. Both play nicely with SQL Server 2005 and 2000, too.
Entity Framework is an ambitious project of Microsoft's Data Stores & Platforms Division's ADO.NET team to raise the level of data abstraction by mapping the relational view of the database's physical layer to the business-entity–oriented view of a conceptual-schema layer. The conceptual schema is the foundation of Microsoft's Entity Data Model (EDM) and SQL Server 2008's Entity Data Platform. EF is the first phase of Microsoft's second attempt to deliver an enterprise-grade object/relational mapping (O/RM) tool that's competitive with the open source NHibernate O/RM tool for .NET and commercial .NET O/RM products, such as LLBLGen Pro.
But there's been considerable controversy in the developer community regarding the suitability of EF's current implementation for domain-driven programming environments. A more recent issue is EF's removal from Visual Studio 2008 and delay of its release to manufacturing (RTM) to the first half of 2008, ostensibly due to difficulties implementing the graphical EDM Designer. Regardless, third-party database vendors are climbing aboard the EF bandwagon. IBM and Oracle have announced their intention to support the EF and EDM. IBM will demonstrate an early build of their EntityClient provider during Tech●Ed 2007's DAT04-TLC chalktalk.
ADO.NET Architect Mike Pizzo says in two blog posts, "Microsoft will be leveraging the Entity Data Model in future versions of Microsoft products such as SQL Server" and "Microsoft envisions an Entity Data Platform that enables customers to define a common Entity Data Model across data services and applications. The Entity Data Platform is a multi-release vision, with future versions of reporting tools, replication, data definition, security, etc. all being built around a common Entity Data Model." Project Astoria and Project Jasper, the two new data-driven "incubator projects" that Microsoft announced at MIX07 in early May 2007, use EF to autogenerate the EDM that handles the relational data. The ADO.NET Team blog and ADO.NET Orcas forums support the Entity Framework and LINQ to Entities.
LINQ is a set of .NET FX 3.5 classes and C# 3.0 and VB 9.0 language extensions that support a common query and transform language for a variety of data domains. What's unique about LINQ is that it substitutes SQL-like standard query expressions, such as:
From c In IEnumerableCollection Where c.Property1
= 1 Order By c.Property2 Descending Select
c.Property1, c.Property2, c.Property3
The emphasized keywords are first-class members of the VB language, so VS 2008 delivers full statement completion and IntelliSense to increase developer productivity. The C# query syntax differs primarily in its use of lower-case keywords and == equality operators.
Here's Microsoft's set of LINQ flavors and their data domains for VS and SQL Server 2008:
- LINQ to Objects is the basic LINQ implementation that lets you query collections of in-memory objects.
- LINQ to ADO.NET defines the set of LINQ flavors owned by the ADO.NET team.
- LINQ to SQL (formerly DLinq) provides a basic O/RM tool with a graphic designer only for SQL Server databases.
- LINQ to DataSets delivers missing query and, especially, join capabilities to DataSets and DataTables.
- LINQ to Entities enables querying the Entity Framework's Object Layer and updating underlying relational tables.
- LINQ to XML (formerly XLinq) lets you query the XML DOM and, with VB 9.0, create XML literals; an incubator project called LINQ to XSD enables strongly typed XML.
Several third-party LINQ implementations for specialized data domains are in varying stages of development—LINQ to SharePoint (lists), LINQ to LDAP (directories), LINQ to RDF (Resource Description Format documents) and LINQ to Amazon (searches) are typical. The ADO.NET Team, Charlie Calvert's Community (C#), and XML Team blogs and the LINQ Project General forum support LINQ (except LINQ to Entities).
The ASP.NET team's Dynamic Data Controls (DDCs), which enable one-click creation of master/details forms for related tables of an SQL Server database, are part of the Microsoft ASP.NET Futures May 2007 release. DDCs are the successor to 2006's BLINQ project, which is based on LINQ to SQL. Andrew Conrad says the ADO.NET team is "looking at integrating Dynamic Data Controls for ASP.NET [with] Jasper," which would move their infrastructure from LINQ to SQL to EF. But Charles Petzold and this developer have reservations about the .NET code generation to create one-click Web sites.
A few lucky Tech●Ed attendees who pre-registered for a Thursday focus group on "LINQ/EDM APIs" will discover the ADO.NET team's "current thinking about the LINQ/EDM APIs we will offer with the Orcas release of Visual Studio" and "get … feedback on how the API is structured." According to ADO.NET the team's Zlatko Michailov, "The [first Entity Framework] CTP is scheduled for June."