Wednesday, August 22, 2007

LINQ and Entity Framework Updates for 8/22/2007

Scott Guthrie and Rick Strahl on Dynamic LINQ to SQL Queries

Scott continues his LINQ to SQL series with LINQ to SQL (Part 8 - Executing Custom SQL Expressions) that shows you how to use the DataContext.ExecuteQuery method and helper methods to fill Table<TEntity> objects with the appropriate subset of persisted data. Scott also describes how to use partial methods to persist updates with custom SQL statements. (Update 8/28/2007.)

Rick's Dynamic Expressions in Linq to Sql is a highly detailed continuation of his earlier posts about issues with dynamic queries in LINQ to SQL. (Update 8/28/2007.)

Mike Taulty covered Dynamic Expressions in his June, 2007 LINQ and Dynamic Queries, Bit More on Dynamic Queries, and More Dynamic Queries posts. (Update 8/28/2007.)

Ian Cooper and Type Mocking for TDD

Ian discusses Scott Bellware's disdain for type mocking in test-driven development (TDD) with strongly-typed languages, such as .NET, and (by inference) LINQ to SQL query results in his 8/24/2007 TypeMock, Static and Dynamically Typed Languages post. An example of type mocking is substituting an in-memory (LINQ to Objects) object graph for the DataContext to speed unit testing, a subject in which I have an interest. Ian came to this conclusion in his Being Ignorant with LINQ to SQL post:

LINQ to SQL is usable with a TDD/DDD approach to development. Indeed the ability to swap between LINQ to Objects and LINQ to SQL promises to make much more of the code easily testable via unit tests than before.

The preceding post refers to Eric Evans' Specification pattern (Domain-Driven Design, p. 224), which Ian adapted to dynamic LINQ queries in his earlier and very detailed Specifications in C# 3.0 post.  Ian provides the following short-form description of the Specification pattern:

[A] specification is a pattern for expressing a rule which you want to use to test an object. A specification is ultimately used to separate two orthogonal concerns: testing objects and the objects themselves.

If you're interested in metadata programming, TDD for LINQ to SQL, or both, don't miss this analysis. (Update 8/28/2007.)

K. Scott Allen and Mocking the DataContext

Scott's Trying Out Persistence Ignorance with LINQ (Part I) is the first of a series that explains how to "abstract the DataContext in a a stubable, fakeable, mockable fashion" to enable swapping DataContext and an "in memory data source" (A.K.A. LINQ to Objects).

ADO.NET Entity Framework Runtime Beta 2 and Tools CTP1

The ADO.NET VNext team managed to deliver the August 2007 CTP with almost a week to spare; see ADO.NET Entity Framework August 2007 CTP for VS 2008 Beta 2 Runtime and Tools Available, which includes abbreviated links to Mike Taulty's posts. The ADO.NET Entity Framework Beta 2 page provides the ADO.NET Entity Framework (EF) Runtime, which requires .NET Fx 3.5, and the ADO.Net Entity Framework Tools Aug 07 Community Technology Preview, a.k.a CTP1, which you must install after VS 2008 and ADO.NET EF Beta 2 runtime, finally delivers the EDM Designer preview! (Update 8/27/2007.)

Mike Taulty and Entity Framework Beta 2 Runtime and Tools CTP1

Mike Taulty has delivered a torrent of brief posts on new EF runtime and tools features.(Update 8/27/2007.)

Beth Massi and Yet Another LINQ to SQL Video

Beth said in her 8/27/2007 Channel 9 Interview - LINQ to SQL and the O/R Designer in VS 2008 post:

I just posted another great interview on Channel 9 with Young Joo talking about LINQ to SQL and the new O/R Designer in Visual Studio 2008. He demos a typical business client-server scenario and shows how LINQ to SQL classes make it much easier to work with relational data in SQL Server 2005. Young also talks about architectures where he sees using LINQ to SQL having the most benefits.

but she probably was drowned out by the clamor about the ADO.NET EF bits. (Update 8/27/2007.)

The XML Team and the XML Schema Editor for VS 2008

It's slightly off-topic, but the XML Team is Announcing CTP1 of the XML Schema Designer as of 8/27/2007. They say:

XML Tools team has released the first CTP of the XML Schema Designer - a graphical tool for working with XML Schemas. The XML Schema Designer is integrated with Microsoft Visual Studio 2008 and the XML Editor to enable you to work with XML Schema definition language (XSD) schemas. If you have used the Visual Studio editor or notepad to edit your schemas, consider downloading this CTP and using it for editing your schema files. You can download it from Microsoft Downloads site. This CTP introduces the Schema Explorer - a tool that helps you navigate, search and work with schema sets. You can view a short video of the new functionality here

Another post that might be lost in the ADO EF melee. (Update 8/27/2007.)

Jim Wooley and Concurrency Checks with Stored Procedures for LINQ to SQL Updates

Jim Wooley discusses one of the issues I encountered during my analysis of LINQ to SQL projects that use stored procedures for CRUD operations. Concurrency checking for UPDATEs and DELETIONs require either original object property values or adding a timestamp column. Adding a timestamp column will make your life much easier than writing stored procs, although you can use . See my earlier

Scott Guthrie and LINQ to SQL Part 8

LINQ to SQL (Part 8 - Executing Custom SQL Expressions) of 8/27/2007 shows you how to substitute your own SQL statements for stored procedures or statements generated from LINQ queries translated by expression trees. This post explains how to use the DataContext.ExecuteQuery<T> method with a custom SQL statement to populate objects.

Julie Lerman and Named Anonymous Types in LINQ Queries

Julie investigates the benefits of identifying LINQ's Select expression explicitly with its own name in Specifying named types in LINQ Queries of 8/27/2007.

Jim Wooley and ThinkLinq

Jim updated his ThinkLinq demo website for VS 2008 Beta 2 on 8/28/2007. The details are at ThinkLinq demo app updated for Beta 2.

Bart De Smet and VB 9.0

Bart promises to start a series of posts on VB 9.0 in his 8/22/2007 Visual Basic 9.0 Feature Focus - Introduction post. Topics include:

Bart usually keeps his promises.

Mike Taulty and the Entity Framework

Mike's authored an improved set of Entity Framework diagrams and more detailed descriptions EF capabilities of in his 8/21/2007 Entity Framework - Various Models to Query, Various Means to Querying post. Mike Taulty Compares LINQ to SQL and LINQ to Entities discusses Mike's first shot at diagramming the EF.

There's still no news from the ADO.NET EF team when the Beta 2 update will be available or when we can expect some documentation from them.

Joe Albahari and LINQPad

Joe Albahari, co-author of the forthcoming C# 3.0 in a Nutshell, has released the Beta 2 version of his beta LINQPad application that lets you write LINQ to Objects, LINQ to SQL, and LINQ to XML queries in a text box and then execute them as if they were included in code. LINQPad also has features that overlap SQL Server Management Studio [Express].

Ben Hall and SQL Metal

Ben Hall's 8/20/2007 The power of SQLMetal post provides a guided tour of SqlMetal.exe's command-line syntax. The O/R Designer finally uses SqlMetal.exe in Beta 2. You'll also need to use SqlMetal.exe in lieu of the O/R Designer if you're working with SQL Server Compact Edition (SSCE), as noted in LINQ to SQL to Support SQL Server Compact Edition.

Beth Massi and LINQ to SQL Videos

Beth reports that "Bill Burrows has done it again and created a series of videos to help get you started with LINQ to SQL in Visual Basic!"

She also offers advice on Converting VS 2005 Projects to VS 2008 - Enabling LINQ.

Scott Guthrie and LINQ to SQL Part 7

LINQ to SQL (Part 7 - Updating our Database using Stored Procedures) continues the series with a lengthy and detailed description of how to use stored procedures for inserts, updates, and deletions. (Updated 7/23/2007.)

Microsoft Research and DryadLINQ

Microsoft Research says this about their Dryad Project, which has goals and techniques in common with Google's MapReduce programming model.

Dryad is an infrastructure which allows a programmer to use the resources of a computer cluster or a data center for running data-parallel programs. A Dryad programmer can use thousands of machines, each of them with multiple processors or cores, without knowing anything about concurrent programming.

DryadLINQ is a subproject with the following objectives:

The goal of DryadLINQ is to make distributed computing on large compute cluster simple, simple enough for ordinary programmers. DryadLINQ combines two important pieces of Microsoft technology: the Dryad distributed execution engine and the .NET Language Integrated Query (LINQ). Dryad enables reliable, distributed computing on thousands of servers for large-scale data parallel applications; LINQ enables the developers to write and debug their applications in a SQL-like query language, with the entire .NET library at their disposal and in the familiar environment of Visual Studio. This combination has produced a simple, powerful, and elegant programming environment for writing large-scale data parallel applications running on large PC clusters.

DryadLINQ appears to be a competitor to Yahoo's Pig (for Hadoop) and Google's Sawzall query languages. Greg Linden analyzes these two in his Yahoo Pig and Google Sawzall post. (The Dryad: Distributed Data-Parallel Programs from Sequential Building Blocks research paper mentions LINQ only in passing.)

Will DryadLINQ morph to LINQ for Dryad when productized? Who knows. (Updated 7/23/2007. Thanks to Mary Jo Foley for the heads-up.)

OakLeaf and LINQ to SQL Issues

I built a simple test harness to see if I could verify an issue raised in a comment by Frans Bouma to my LINQ to SQL Query Execution with LoadOptions Specified post. David Hayden's LINQ To SQL - Query Tuning Appears To Break Down In *More Advanced* Scenarios post reports on the issue he discussed in the context of the LINQ to SQL Visualizer.

My test harness confirmed the current requirement for one query per Customer object to return associated Order and Order_Detail objects. Apparently LLBLGen Pro's can do the same with three queries for all Customer, Order, and Order_Detail objects. It also confirmed the symptoms of the (finally-admitted) bug reported by Howard Richards in this LINQ bug - just me? LINQ Project General forum post, but not the bug itself.

However, I'm finding what appears to be an even worse problem: The entity table doesn't work as expected when you specify a DataContext.LoadOptions property value to eager-load Customer objects' associated Order and Order_Detail objects. Clicking the Get US Customer button runs 14 T-SQL queries to load 13 Customers and associated objects, which should now be in the entity table (and in memory). However, clicking Get Orders and Get Order_Details on the same DataContext instance issues the same 14 T-SQL queries. This problem doesn't occur with deferred loading enabled.

You can expect a detailed post and a downloadable copy of the project for this test harness later today:

I'm working on a similar test harness to demonstrate LINQ to SQL's lack of support for substituting stored procedures for T-SQL statements to populate DataContext.Table<TEntity> objects.

Update 8/22/2007, 6:00 PM PDT: The post with the downloadable code is Eager Loading Appears to Cause LINQ to SQL Entity Table Problems.