Tuesday, November 06, 2007

LINQ and Entity Framework Posts for 11/5/2007+

Note: This compendium is updated daily or more often, depending on availability of articles. (Updated November 6, 7, 8, 9, 10, and 11, 2007)

Rick Strahl Posts Sample Code for His DevConnections LINQ Presentation

Rick's My DevConnection Fall '07 Session Slides and Sample Links post of November 10, 2007 includes a link to the source code for his "Building a LINQ-Based Business Layer for ASP.NET Applications" session example, which he describes as follows:

This session's sample provides a small business framework wrapper for LINQ to SQL (discussed here) as well as a sample application that uses the business framework for all of its business logic and LINQ to SQL for all data access. The sample is a small time tracking application that allows punching in and out, viewing of entries, and a basic time report, as well as security and a few other related features.

The preceding quote's link is to Rick's A simple Business Object wrapper for LINQ to SQL post of September 27, 2007, which provides a detailed architectural description, class diagram, and some explanation of coding techniques. The sample code runs under VS 2008 Beta 2; Rick promises and update for the RTM version.

SubSonic will be the "Convention-Driven Toolset for Microsoft’s New MVC Framework" for ASP.NET

From the "How Did I Miss This?" department: Kauai-based developer Rob Conery, ASP.NET MVP and creator of the SubSonic open-source object-relational mapping (O/RM) tool and data abstraction layer (DAL) combined with Web page scaffolding features, goes to work for Microsoft on Monday, November 12, 2007. He'll be working to "build out SubSonic a little more … in a fulltime capacity with [Microsoft]."

John Galloway suggested more than a year ago (on August 30, 2006 to be specific) that Microsoft should ship SubSonic (formerly called ActionPack) with Atlas. According to his post, which provides examples of SubSonic's scaffolding and LINQ-like query language, John likes SubSonic "a lot better than MonoRail."

The upshot is that the ASP.NET team is adopting an open-source (Mozilla Public License 1.1) O/RM instead of LINQ to SQL or the Entity Framework as the Controller's DAL. Scott Guthrie's decision to adopt SubSonic might be responsible for the apparent demise of Project Jasper (see Has Project Jasper Been Swallowed by a Black Hole? of November 1, 2007).

For more details see SubSonic will be the "Convention-Driven Toolset for Microsoft’s New MVC Framework" for ASP.NET of November 11/2007.

Added: 11/10/2007 Updated: 11/11/2007

Mike Taulty's Tech*Ed Developers 2007 LINQ Presentation Follow-Ups

These three November 10, 2007 posts supplement Mike's three LINQ-related presentations in Barcelona (see Tech*Ed Developers 2007 to Include 10 LINQ-Related Presentations):

TechEd Europe - Follow Up 1. In LINQ, "Where" == "AndWhere" offers samples of cascaded queries with mutually exclusive Where clauses that return an empty sequence. It's a mystery to me why the obvious result raised a question. However, Mike does make the point that IEnumerable implementations of LINQ queries don't support a direct equivalent of an SQL WHERE Region = 'CA' OR Region = 'OR' [OR Region = 'WA'] clause, but LINQ to SQL IQueryable implementations do.

Mike suggests Union queries for uniformity between LINQ to Objects and LINQ to SQL syntax. However, I recommend abandoning uniformity and using the Contains extension method with LINQ to Objects:

Dim strStates As String() = New String() {"CA", "OR", "WA"}
Dim States = From St In strStates Select St
Dim WestCoastCustomers = _
CustomerList.Where(Function(c) States.Contains(c.Region))

What would really be nice is OrWhere() as a Standard Query Operator.

TechEd Europe - Follow Up 2. Serializing Expressions discusses a question about a LINQ to SQL architecture that "serializes this LINQ query over the network to a remote middle-tier server and then that server executes the query before serializing the result-sets back to the client."

As Mike notes:

Both LINQ to SQL and LINQ to Entities will allow you to execute a string-based query and get back an object-based result-set and that's the way I'd go if I needed this kind of functionality.

But why send a LINQ string? LINQ is all about replacing brittle query strings with strongly typed, compiler-checked LINQ queries in source code. Sending an SQL statement in a parameterized query string is simpler, faster, and more foolproof. TechEd Developer 2007 was held in Barcelona, best known for Catalan architect Antoni Gaudí's Sagrada Família towers; perhaps Gaudí's fantastically intricate designs influenced the questioner's software design.

TechEd Europe. Follow Up 3 contains the following links:

Beth Massi Interviews Bill Horst on Type Inference in VB 9.0

The title of Beth's Channel 9 Interview: Type Inference in Visual Basic with Bill Horst (Beth Massi) post of 11/8/2007 says it all. The direct link to the 19:39 video clip over a screen cam capture is here.

Added: 11/9/2007

Entity Framework FAQ from Danny Simmons

Danny Simmons posted Entity Framework FAQ on November 8, 2007 at about 3 am from his Las Vegas hotel room. (He's attending DevConnections 2007 but not presenting.)

The FAQ currently has an Introduction and 19 topics ranging from Architecture/Patters to Serialization. Danny pasted the content from his and the ADO.NET Team's previous blog posts and answers to questions in the ADO.NET (Prerelease) forum, a.k.a., the Entity Framework forum.

Added: 11/8/2007

MIX 08 Sessions on ADO.NET Data Services and the Sync Framework

MIX 08 (a.k.a. "The Next Web") will be held in the Venetian Hotel, Las Vegas, March 5 - 7, 2008. Here are two of the first 21 sessions listed that relate to LINQ and the Entity Framework:

REST Easy with the ADO.NET Data Services Framework
Speaker: Mike Flasko
Audience: Technical
Session Type: Breakout

Learn how to create and interact with the ADO.NET data services framework (codename "Astoria") from JavaScript, .NET, and Microsoft Silverlight.

Real World Implementations Using Sync Services for ADO.NET
Speaker: Philip Vaughn
Audience: Technical
Session Type: Breakout

See best practices for building multi-tier applications that synchronize data between Microsoft SQL Server 2008 and thousands of clients using SQL CE to provide an offline experience.

This looks to me to be more evidence of the link between Astoria and the Sync Framework, except that the latter presentation appears (at the moment) to be limited to the original member of the Sync Framework.

Added: 11/8/2007

Beth Massi's Visual Studio Tip of the Day RSS Reader

Beth's Visual Studio Tip of the Day Browser post of November 7, 2007 demonstrates a special-purpose feed reader that uses a LINQ to XML query to parse the RSS feed from Sara Ford's blog and display a list of tips of the day ("Did you know ... ?" items) in a DataGridView and show the body of the selected tip in a text box. The complete app is available to download.

Added: 11/8/2007

The VB Team: Compiled LINQ to SQL Queries Redux

Back in July 2007, Rico Mariani (then Microsoft performance czar, now Chief Architect of Visual Studio) wrote a five-part series named DLinq (Linq to SQL) Performance Part N. The series ended with Rico claiming that he achieved 93% of the performance of the underlying SqlClient/SqlDataReader data provider with compiled LINQ to SQL query expressions that exaggerate LINQ overhead. I wasn't able to duplicate his results at the time because he had VS 2008 Beta 2 and I didn't. It was clear, however, that compiling the query gave a significant improvement in execution speed.

The VB Team's Doug Rothaus posted LINQ Cookbook, Recipe 10: Pre-compiling Queries for Performance on November 7, 2007. Doug's test harness uses a DataGrid view to display orders for a selected Northwind customer. My test harness that I described in Rico Mariani's DLinq Performance Tips (Part 2) and Compiled Queries executed the compiled and uncompiled versions of query similar to the one Rico used 500 times to obtain what I believe is a more accurate timing method. My Rico Mariani's DLinq (LINQ to SQL) Performance Tips (Round 3) has links to Rico's later posts. My posts include tabular timing data to compare performance. I never came close to 93% of the performance of the SqlClient/SqlDataReader combination.

Added: 11/7/2007

Julie Lerman: Astoria to Become ADO.NET Data Services

Julie's November 6, 2007 Astoria - what's coming after the prototype post from DevConnections 2007 (Las Vegas) reports on Mike Flasko's VDM303: Project Astoria: Data Services for the Web presentation.

Aside from the name change, here are the changes since Pablo Castro's Astoria data sources and system layering post of September 27, 2007:

  • Data will be formatted as either JSON or ATOM. Plain old XML (XML) is out, as is Web3S. I expressed my disdain for Web3S in Deciding Astoria's Final URI Addressing Scheme of September 23, 2007. However, I think abandoning POX is a serious mistake, expecially when you consider that a future Silverlight version is scheduled to get LINQ for XML.
  • LINQ to Astoria will translate LINQ query expressions to URIs that will correspond to the final URI addressing scheme, which presumably won't include Web3S syntax.

Hopefully, the Astoria team will change their minds on abandoning POX as a wire format. Dare Obasanjo's Why GData/APP Fails as a General Purpose Editing Protocol for the Web post of June 8, 2007 and One Protocol to Rule Them All and in the Darkness Bind Them article of October 9, 2007 explains why the Atom Publishing Protocol (RFC 5023) "is unsuitable as the data access protocol for a large class of online services." 

Added: 11/7/2007

Anders Norås: Quaere Offers LINQ-Like Deferred Execution

Anders' Lexical Closures, Deferred Execution and Kicker Methods post of November 6, 2007, explains that Quaere ("LINQ for Java") does, indeed, offer deferred execution. Quaere uses the iterator method on Java's Iterable interface as its "kicker method."

The term kicker method comes from Chris Wanstrath’s Ambition project (a.k.a. "LINQ for Ruby").

Added: 11/7/2007

Dinesh Kulkarni on Enums in LINQ to SQL

Dinesh Kulkarni proves that LINQ to SQL supports enums in his Less known LINQ to SQL features 1: how to map an enum post of 11/5/2007. His example replaces the Northwind Shipper entity with:

public enum ShippingCompany {

and provides a pair of classes that demonstrate its use with the Orders.ShipVia property as a ShippingCompany or Nullable<int> (int?) type that LINQ queries.

Added: 11/6/2007

Off-Topic: Microsoft Opens the Sync Framework's Kimono

I've written several posts and a couple of Visual Studio Magazine articles about Sync Services for ADO.NET, SQL Server Compact Edition (SSCE), and related topics, so I've recapped Monday's news on these and related topics in Microsoft Releases Sync Framework CTP1 of November 5, 2007.

Added: 11/6/2007

Update 11/8/2007: This item might not be as off-topic as I initially believed. Mary Jo Foley mentioned in her November  5, 2007 More details emerge on Microsoft’s online-offline sync platform article:

Astoria supports the Atom Publishing Protocol (APP) as a serialization format and the Sync Framework supports Ray Ozzie's Simple Sharing Extensions (SSE) for Atom and RSS. This means that SSE-enabled Astoria data sources could participate in bi-directional, peer-to-peer synchronization operations.

Update 11/9/2007: Steve Lasker posted in his November 7, 2007 Presentations & Demos from Tech Ed Barcelona 07 post links to the slide decks and demo code for his SQL Server CE and Sync Services presentations. The demo code is for a post-Beta 2 release of VS 2008, but Steve says "you can open the files in B[eta] 2."

Update 11/14/2007: Rafik Robeal points to a Channel9 Milind Lele interview, Offline Data Synchronization Services in Visual Studio 2008, by Beth Massi that includes a demo of the Sync Services designer.


Anonymous said...

Why send a string? Generally, I wouldn't but I got asked the question :-) Some thoughts;

1) Dynamically making a string is way easier than dynamically creating an expression.

2) It might not make sense to share a server type with a client and keep them tightly coupled like that. If you don't have a type that's IQueryable and visible to the client then you can't really write that LINQ query in the client with the benefit of strong typing.

3) Pragmatically - as the post said, AFAIK the expression won't serialize anyway so if that's the case then it's a non-starter and string becomes your only option for sending some definition of a generic query from a client to a server.

4) Generally, I don't see me wanting to send string or an expression. I see me calling well-defined methods on a service interface that I define but I was asked the question :-)