Sunday, November 18, 2007

Link and Entity Framework Posts for 11/19/2007+

Note: This compendium is updated daily or more often, depending on availability of articles. Updated November 20, 21, 23, 24 and 25, 2007.

Keith Farmer Takes on N-Tier Patterns with LINQ to SQL

From the "How Did I Miss This" department? (I missed it because Keith has been a infrequent poster—five posts from March to October 2007.)

Keith's LINQ and 3-Tier Dogma post of November 6, 2007 encourages developers not to be "pattern bigots" (my terminology) when it comes to multi-tier LINQ to SQL implementations. He says, undoubtedly in response to Dinesh Kulkarni's that LINQ to SQL Has No "Out-of-the-Box Multi-Tier Story:

The 3-Tier Model is just a pattern. And, like all patterns, It is meant to serve our needs, not the other way around.

He then goes on to examine the issue of the purity of separation of the data and logic layers:

    • Contractual purity (there is a set of well-known interfaces between the tiers)
    • Binary purity (the types are completely separate in each tier, *and* there is a contract between each)

and explains the advantage of abandoning binary purity in favor of contractual purity. He concludes:

The encapsulation of the data context is the creation of the logical layer.

His follow-on Encapsulation and LINQ to SQL post of November 13, 2007 provides a concrete implementation of encapsulating an IQueryable with a TableView class and an abstract class for wrapping a DataContext with a DataContextWrapper class. The article concludes with a sample implementation of DataContextWrapper.

Added: 11/25/2007

Bill McCarthy Excises LINQ to XML's Duplicate Namespace Declarations

Bill's Cleaning up your XML literal namespaces post of November 24, 2007 includes the code for a short utility program that removes redundant xmlns declarations from elements other than the root when you use the Element1.Add(Element2) method.

Added: 11/24/2007

CoDe Magazine Focuses on Data Access with LINQ and the Entity Framewok

The Data Programmability CoDe Magazine Focus Issue of December 2007 includes the following articles focusing on LINQ:

and these devoted to the Entity Framework:

All authors are from Microsoft's Data Programmability group.

Other articles cover SQL Server Compact Edition (SSCE) 3.5 and the new Sync Framework.

Added: 11/24/2007

LINQ to MPI.NET in Development at Phoster Incorporated

Adam Sobieski, a Phoster Incorporated developer, currently is completing development of System.Collection and System.Collection.Generic implementations for MPI.NET, which is a high-performance message-passing interface for .NET. According to his Update: LINQ to MPI.NET post of November 24, 2007, Adam plans to write a LINQ implementation for the collections.

Here's the University of Indiana's description of MPI.NET:

MPI.NET is a high-performance, easy-to-use implementation of the Message Passing Interface (MPI) for Microsoft's .NET environment. MPI is the de facto standard for writing parallel programs running on a distributed memory system, such as a compute cluster, and is widely implemented. Most MPI implementations provide support for writing MPI programs in C, C++, and Fortran. MPI.NET provides support for all of the .NET languages (especially C#), and includes significant extensions (such as automatic serialization of objects) that make it far easier to build parallel programs that run on clusters.

Adam's interest in LINQ to MIT.NET stems from his work on distributed AI applications using C# 3.0 and .NET 3.5. According to Adam's RETE, CEP, ESP post of the same day:

There are two types of machine reasoning popular today: CEP/ESP and RETE. There’s also combinations (Bruno Berstel, Alexandre Alves). I’m thinking P2P distributed applications with RETE/ESP using LINQ programming practices will allow for rapid-prototyping of some sophisticated AI applications. I’m presently brainstorming some developer libraries in this area (Semantic Grid, Knowledge Grid).

It's not yet clear to me how LINQ to MPI.NET would fit in with the ParallelFX program and PLINQ. PLINQ is directed to multi-core processors. My PLINQ Gathers Momentum post of December 8, 2006 (last updated 7/30/2007) includes many links to early PLINQ articles.

Added: 11/24/2007

Frans Bouma Reaches the Ninth Wave of LINQ to LLBLGen Pro Development

LINQ to LLBLGen Pro is coming along nicely using the LLBLGen Pro API to emulate LINQ to SQL but with the API's database-agnostic SQL intermediate language (IL). Frans is dropping the Skip() and Take() methods in favor of the API's pageNumber and pageSize values for paging, bypassing CROSS APPLY for SelectMany(), and implementing GroupJoin() and DefaultIfEmpty().

Frans' Developing Linq to LLBLGen Pro, part 9 post of November 23, 2007 provides the details of the trade-offs in implementing the preceding Standard Query Operators (SQOs) with the LLBLGen Pro API for multiple RDBMSs.

Note: The "Ninth Wave" refers obliquely to Eugene Burdick's prize-winning 1963 novel, which uses the Celtic ninth wave as a metaphor and Northern California as a backdrop.

Added: 11/23/2007

Bart De Smet Releases RTM Version of LINQ to SQOs

Back in the early days of the LINQ CTPs for VS 2005, Bart De Smet created a custom implemention of the LINQ Standard Query Operators (SQOs). His LINQSQO goes RTM post of November 22, 2007 announces that the RTM version of LINQ to SQOs is available on CodePlex.

The source code contains 148 unit tests that you can run with Visual Studio 2008 Pro or higher. This screen capture shows VS 2008 Pro's Test Results window displaying a few unit test results on the Query class library:

Added: 11/23/2007

Regenerating Original Entities from Entity Framework's ObjectStateManager

Neither the Entity Framework's ObjectContext or LINQ to SQL's DataContext is serializable, so you can't access the ObjectContext.ObjectStateManger's or the DataContext.Table<T>'s original values for an entity.

Danny Simmons' Creating an original value object from the separate values stored in the ObjectStateManager post of November 21, 2007 shows you how to create an an entity with all original property values populated from the partial (changed-value(s) only) data in the ObjectStateManager. Presumably, this entity would be serializable for cross-process transport.

Note: Don't confuse the term "value object" in Danny's post time with "complex objects" (a.k.a. Martin Fowler value objects.)

This post relates to Danny's earlier post about serialization depth (see below.)

Added: 11/23/2007

Alex James Joins the ADO.NET Team as Program Manager for Metadata

Alex James has moved from New Zealand to Seattle to join the ADO.NET Team as Program Manager for Entity Framework (EF) metadata. His initial Introductions blog post appeared on November 9, 2007 but the other ADO.NET EF folks didn't post an announcement, so I missed it. (Thanks to Julie Lerman for the heads-up).

Alex added the following EF-related posts after November 9:

Alex's posting frequency bodes well for his participation in the EF community.

Added: 11/23/2007

Danny Simmons on Serializing Entity Framework Object Graphs

Serializing Entity Framework (EF) object graphs to enable multi-tier data access scenarios incurs the same problems that caused Dinesh Kulkarni to admit that LINQ to SQL Has No "Out-of-the-Box Multi-Tier Story, as discussed in my post of October 18, 2007.

By default, the current EF CTP2 doesn't serialize associated entities. This omission requires that the client to make a method call for each set of instances required and then reconstruct the relationships locally. In this January 27, 2007 Entity Web Service: Returning Category thread Danny recommends creating a facade object to contain associated objects. The thread starter uploaded the alpha 0.1 version of a facade implementation to CodePlex.

Binary serialization for EF entities preserves associated entities but is limited to remoting or services on intranets because the payload won't pass through Internet firewalls. Binary serialization creates a deep clone of associated objects; that is, references to shared objects turn into individual copies of these objects. This results in what's called a "data explosion" and very large service/remoting payloads.

Danny's Question: Deep serialization of an object graph--how deep should it go? post of November 20, 2007 discusses three potential serialization options for future CTPs or versions:

  1. Return the entire object graph with 1:many and many:1 associations intact. Such graphs generate extremely large payloads and won't serialize with the default DataContractSerializer of Window Communication Foundation (WCF) because of cyclic references (also called cycles.)
  2. Remove the 1:many associations to prevent conflicts when multiple operations return graphs that include duplicate objects. LINQ to SQL implements this option by not serializing any 1:many associations. This is required to prevent cyclic references.
  3. Specify subgraphs on a method-by-method basis.

To serialize complete graphs with 1:many and many:1 (bidirectional) associations intact requires a rather complex workaround for the Windows Communication Framework's default DataContractSerializer or use of the NetDataContractSerializer.

Note that neither ObjectContext nor DataContext objects are serializable, which limits their identity managers and change trackers to in-process use.

Unless the ADO.NET team chooses one of the three options for EF v1, EF won't have an "out-of-the-box multi-tier story" either.

I'm working on a post with some examples and an analysis of a choice between options 2 and 3. Click here for a preview of the Serializing Object Graphs Without and With References post of November 21, 2007 (updated 11/23 and 11/25/2007) with downloadable files containing examples of serialized XML Infosets and schemas generated by the DataContractSerializer (DCS) and NetDataContractSerializer NDCS. Test with in-memory List<T> collections show that the NDCS serializes and deserializes bidirectional associations correctly.

Added: 11/20/2007 Updated: 11/23/2007 and 11/25/2007

Zlatko Michailov: Compiling LINQ to Entities Queries

Zlatko's previous post, Behavior of Variables in LINQ to Entities Queries of November 16, 2007, recommended compiling queries to remove LINQ to Entities' uncertain treatment of variables assigned literal values as constants or parameters.

Today's brief post, LINQ to Entities: Compiled Queries, explains the compilation process, which, like compiling LINQ to SQL queries, improves performance. Parameters are explicit for compiled queries.

Bill Horst of the VB Team: Converting SQL to LINQ Series

The VB Team posted the first of a series of articles, Converting SQL to LINQ, Part 1: The Basics (Bill Horst), on 11/19/2007. This episode covers basic LINQ query syntax. Future articles will cover LINQ equivalents to these T-SQL keywords:

  • Functions (Scalar and Aggregate)
  • Joins
  • UNION, TOP and Subqueries

InterLINQ Provider Alpha 0.2 Serializes Expression Trees

Pascal Schaefer and Manuel Bauer of the Swiss Software Solution Center have posted the Alpha 0.2 release of the InterLINQ library, including sample implementations for NHibernate, LINQ to SQL and LINQ to Objects, and a help file.

InterLINQ serializes the expression tree of a LINQ query so you can transport it across machine boundaries and execute it with a LINQ implementation on a server. It's up to you how to return the query result set to the client. LINQ to SQL lets you mark its partial classes as unidirectionally serializable, so classes with m:1 EntityRefs and 1:n EntitySets lose their EntityRefs because of the circular reference.

Tip: Right-click the InterLinq.chm file, choose properties, and click the Unblock button to read the help pages.

Danny Simmons: Entity Framework Beta 3 Due in a Few Weeks

From an answer to a question by Henrik Dahl in the ADO.NET (Pre-release) forum:

We're working hard to wrap up the last round of testing and bug fixes on the EF and the EF designer.  The plan is to release beta 3 of the EF/CTP 2 of the designer in a few weeks (think "early December").

Thanks to Julie Lerman for the heads-up.

Paul Stovell Explains SyncLINQ for Real and Derived Client State

In his Why SyncLINQ should matter to you post of November 15, 2007 and follow up Three categories of SyncLINQ queries article of November 16, Paul explains how derived state differs from real state in desktop client apps. He als demonstrates how SyncLINQ keeps derived state synchronized with real state as the data underlying real state changes.

Paul's in the process of coding the first SyncLINQ iteration. He writes:

In terms of right now, I have just implemented the first set of aggregate extensions, and I have a basic dependency system working. Over the coming week I’ll be working to implement an operator, and refactor much of the dependency system to support the overloads above.

His Introducing SyncLINQ post of October 16, 2007 includes a seven-minute video clip of SyncLINQ in action.

Note: There's still no library to download.

Mary Jo Foley: VS 2008 Rumored to be Available Monday 11/19/2007

Mary Jo writes "Sources say Microsoft will announce availability on Monday, November 19" in her "Visual Studio 2008 to go gold as soon as Monday" column of November 18, 2007.

eWeek's Daryl K. Taft quotes the MSDN Subscriptions WebLog post of November 16, 2007 in his Visual Studio 2008 Is Imminent post of November 17, 2007 as stating "Visual Studio 2008 is anticipated out early next week, with availability for subscribers." However, on November 18, 2007, the posts first sentence read "Visual Studio 2008 is anticipated out very soon, with availability for Subscribers." I assume the blog author edited the post without revision marks.

Be sure to review Dinesh Kulkarni's two LINQ Project General Forum posts about Beta 2 to RTM changes fo LINQ to SQL:

Jim Wooley suggests:

  • Open the DBML file as XML and change the UTF encoding from 16 to 8. Otherwise the compiler will complain about the DBML file's format.

Update 11/19/2007 1530 PST: LINQ to SQL Beta 2 to RTM Breaking Changes has been published as a downloadable .docx file. Charlie Calvert's Visual Studio 2008 Available for Download post has links to independently published files, such as the C# LINQ and language samples for Visual Studio 2008, which were updated 11/9/2007. The Visual Studio 2008 Samples page has a current list of samples for VB and C#.

Hopefully, the LINQ to Objects, LINQ to XML and LINQ to DataSets teams will post Beta 2 to RTM changes, if any, soon.

Update 11/19/2007 0700 PST: The rumors were correct. Microsoft made the download available but the MSDN servers were throwing  "Server Error in '/' Application. The file '/home.aspx' has not been pre-compiled, and cannot be requested." errors from the entry page for the download: ..., which is not a good sign. Subsequently, the error messages changed to the more common "Server too busy."

Update 11/19/2007 0900 PST: Servers finally became operable.

Update 11/19/2007 1200 PST: Scott Guthrie has posted Visual Studio 2008 and .NET 3.5 Released with a summary of new features and links to related resources. Guy Burstein notes that you can download the Visual Studio 2008 and .NET Framework 3.5 Training Kit, too (120MB.)

Dinesh Kulkarni Writes a Common Base Class for LINQ to SQL Queries

If you want to "encapsulate a pattern and common behavior" across multiple business entities generated by SqlMetal.exe or the O/R Designer, Dinesh's "LINQ to SQL Tips 2: how to use common base class for all entities post of November 9, 2007 (released November 18, 2007) shows you how.

Danny Simmons: Handling Conditional Relationships in the Entity Framework

If your DBA has set up Relationships from Hell as described in Danny's An Interesting Relationship Mapping Scenario post of November 17, 2007 there might be a solution that works with Entity Framework v1, but it's more likely that you'll need to model a containment relationship with v2 (or later).

The many:one relationships Danny describes are defined by foreign key and type column values. The foreign key value points to the primary key of a table that's selected from a group of tables by a value in a type column. Only one many:one relationship occurs at any instance.

Danny describes a containment relationship thusly:

The basic idea of this construct is that "child" entities may be related to one or more "parent" entities but only one parent at a time.

The relationship Danny describes doesn't fit with my understanding of a containment relationship, which is more in tune with that described in the Object Containment topic of class notes for a Database Systems and Structures class at Simon Fraser University.


Alex James said...

Hey Roger,

I just wanted to say thanks for the link and don't hesitate to contact me if you have any questions...

(alexj at microsoft dot com)

Keith J. Farmer said...

(From the "I missed it as well" department...)

The things I find when Googling myself. :)