Wednesday, May 21, 2008

LINQ and Entity Framework Posts for 5/19/2008+

Note: This post is updated daily or more frequently, depending on the availability of new articles.

Has LINQ to SQL Reached Legacy Status Less than Three Months after Launch?

LINQ to SQL was the only new data-access implementation to be included in Visual Studio 2008 when it "launched" with SQL Server 2008 and Windows Server 2008 in a series of "Heroes Happen Here" extravaganzas that started on February 27, 2008.

Judging from my Is the ADO.NET Team Abandoning LINQ to SQL? post of May 21, 2008, Microsoft appears to have ceased further development of LINQ to SQL, based on the lack of new and promised features in the LINQ to SQL SP1 Beta.

Added: May 21, 2008

Francois Vanderseypen Offers a Well-Documented Demo of a Web Client Software Factory Project that uses WCF, WF and LINQ to SQL

His Frameworks and directions (Kyiv presentation, May 2008) post of May 19, 2008 includes a link to download a large-scale Northwind Factory v.2.1 sample project that combines the Web Client Software Factory (WCSF) from CodePlex with LINQ to SQL, Windows Communication Foundation, and Workflow Foundation. The project, which builds a complete multi-tiered, Model-View-Controller (MVC) pattered Web site, includes a 26-page illustrated NorthwindFactory.docx documentation file. NorthwindFactory.docx is the last file in the .zip archive.

Francois's later Linq to SQL and Workflows post of May 21, 2008, casts doubt on the compatibility of LINQ to SQL data layers with the Workflow Foundation and raises other commonly blogged LINQ to SQL issues. He concludes:

All this leads somehow to the conclusion that [LINQ to SQL] was really not designed well to fit with the rest of the .Net 3.5 framework. Great idea, but not too well implemented. Let’s hope the final release of the Entity Framework (around [A]ugust with .Net 3.5 SP1) will bring some cures.

Francois works for Materialise Dental NV in Leuven, Belgum, the developer of "a range of products and services to aid dental specialists in the treatment of their patients," including "the SimPlant range of solutions for Computer Guided Implantology."

Added: May 21, 2008

Randolph Cabral Adds Business Entity Classes to His N-Tier LINQ to SQL Project

In Exploring N-Tier Architecture with LINQ to SQL (Part 4 of n) of May 21, 2008, Randolph "attempt[s] to build out the domain model and use it in our web UI layer to demonstrate how we could interact with the business entities."

Added: May 21, 2008

Ben Hall Recommends When and How to Use Stored Procedures vs. User-Defined Functions with LINQ to SQL

Ben's Linq to SQL Stored procedure vs Functions post of May 21, 2008 provides a detailed analysis of when to substitute user-defined functions (UDFs) for stored procedures in LINQ to SQL data-access scenarios.

Added: May 21, 2008

ASP.NET Dynamic Data Website Wizard Gets Major Overhaul in May 20 Update

Scott Hunter's May 20th Refresh of Dynamic Data is now Available post to the ASP.NET Forums of May 21, 2008 lists 11 significant changes to the Dynamic Data Website Wizard. An important upgrade is replacing details, edit, and insert ListView with FormView controls.

The Dynamic Data Runtime gets a few bug fixes, as well as UI and validation tweaks.

You can download the Dynamic Data Runtime and Templates from the MSDN Code gallery.

Added: May 21, 2008

Frans Bouma Red-Flags VB's Aggregate LINQ Reserved Word

According to his VB.NET: Beware of the 'Aggregate' keyword (updated) post of May 21, 2008, executing

Dim max = Aggregate o in metaData.Order Into m=Max(o.EmployeeID)

returns all Order entities and executes the Max() aggregate in the client's memory. Surprisingly, Frans reports in his update that the problem doesn't occur with DateTime or String values.

Added: May 21, 2008

Dean Whittaker Explains How to Use LINQ to SQL's DataContext Object to Recreate Test Databases

It's a common practice to mock database operations when using Test-Driven Development (TDD) to improve performance. If you don't mock the database, it's a good practice to recreate it each time your unit tests run to update it.

Dean Whittaker shows you how to do this in his Using Linq's DataContext to (re)create your database for testing post of May 21, 2008.

Added: May 21, 2008

Mike Taulty Extend's Julie Lerman's Analysis of EF Query Execution to LINQ to SQL

Mike's "When Do Queries Execute" post of May 21, 2008 extends Julie's discovery that stored procedures execute when invoked with ExecuteMethodCall() rather than when the data is needed (see below) to LINQ to SQL queries.

However, LINQ to SQL queries that invoke table-valued functions do so with CreateMethodCall(), which defers data retrieval until the data is required.

Added: May 21, 2008

Aaron Skonnard Describes the .NET 3.5 SP1 DataContractSerializer's New POCO and Cycle Capabilities

The Windows Communication Foundation (WCF) Data Contract Serializer (DCS) has two important new capbilities:

  1. Capability to serialize complete object graphs with associations that create cyclic references (a.k.a. bidirectional serialization or cycles) for services without a hack.
  2. Capability to serialize plain old CLR objects (POCOs) by removing the requirement to decorate classes with [DataContract] and [DataMember] attributes.

Aaron Skonnard takes on #1 in his DataContracts and object references post of May 14, 2008 and #2 in his detailed DataContracts without attributes (POCO support) in .NET 3.5 SP1 post of May 13, 2008. I missed Aaron's posts due to the activity surrounding release of .NET 3.5/VS 2008 SP1 Beta.

Prior to SP1, you could enable serializing graphs with cycles by setting the PreserveObjectReferences argument to true in the DCS's constructor. (Failing to do this raises an exception when the DCS encounters a cycle in the source object.)

However, you can't enable this option directly when you use the DCS with WCF in a service operation. Instead, you need to subclass DataContractSerializerOperationBehavior and override the CreateSerializer() method with the code described in Sowmy Srinivasan's seminal Preserving Object Reference in WCF post of March 26, 2006.

My LINQ to SQL and Entity Framework XML Serialization Issues with WCF - Part 1 post of October 9, 2007 and Serializing Cyclic LINQ to SQL References with WCF of October 30, 2007 cover issues with cycles in LINQ to SQL, which also apply to the Entity Data Model.

The latter post quotes a response to the System.ServiceModel.CommunicationException - The socket connection was aborted... question in the WCF forum by Microsoft's Ed Pinto:

Please be aware that there is no interop story for the preservation of object references.

I observed that "[t]he rumor is that Microsoft deliberately made it difficult to set this attribute value to discourage non-interoperable bidirectional serialization scenarios." It will be interesting to see if Microsoft has come up with an interop story to accompany SP1.

Added: May 21, 2008

Danny Simmons Updates Entity Framework FAQs

His New in version 0.5 of the FAQ… post of May 21, 2008 provides links to:

Added: May 21, 2008

Igor Ostrovsky Offers Seven Unusual Uses for LINQ to Objects

Igor is an infrequent poster but his 7 tricks to simplify your programs with LINQ entry of May 18, 2008 contains the following interesting examples:

  • Initialize an array
  • Iterate over multiple arrays in a single loop
  • Generate a random sequence
  • Generate a string
  • Convert sequences or collections
  • Convert a value to a sequence of length 1
  • Iterate over all subsets of a sequence

Thanks to Scott Guthrie for the heads-up.

Added: May 21, 2008

Matthieu Mezil Offers an Illustrated Introduction to Entity Framework with Advanced Topics

Matthieu's Entity Data Model Mapping: Beyond the Basics article for DataDeveloper.net starts by creating the requisite Northwind Entity Data Model with the Wizard, but then goes on to cover:

  • Many to many relationships
  • Entity splitting
  • Mapping with added conditions
  • Table Per Type (TPT) inheritance
  • Table Per Hierarchy (TPH) inheritance
  • Complex types
  • Create/update/delete SSDL functions
  • The SELECT SSDL function
  • Performing database operations based on views

Added: May 21, 2008

Matt Berseth AJAXifies the DetailsView of a Master/Details Web Form

Regardless of whether the page's DataGrid and DetailsView controls' data source is an ObjectDataSource, LinqDataSource or EntityDataSource, the AJAX Control Toolkit's ModalPopup with a DetailsView on an UpdatePanel improves the data editing experience.

Matt's Master-Detail with the GridView, DetailsView and ModalPopup Controls post of April 29, 2008 updates his prior version with a spiffed-up page design and now emulates saving changes to the back-end tables. Source code is available for download, and it's not much work to substitute a LinqDataSource or EntityDataSource for the ObjectDataSource.

Click here for a live demo.

If you're interested in AJAXifying DataGrids, read Matt's 7 simple steps to ajax-enable your ASP GridView

Thanks again to Scott Guthrie for the heads-up.

Added: May 21, 2008

Agnes Molnar Continues Her LINQ4SP Demonstrations

Hungarian SharePoint MVP Agnes Molnar (a.k.a. Aghy) shows her replacement for Bart DeSmet's LINQ to SharePoint implementation creating a lookup to a list in her LINQ4SP - How to create a new item with a lookup to another list? post of May 20, 2008. The post includes a link to a 02:30 silent screencast.

Ryan Hauert Updates an EF Three-Level Table per Hierarchy Entity with Stored Procs

Mapping ImportFunctions to stored procedures for updating base (Person) and inherited (Employee and Manager) types isn't a strictly intuitive process, so Ryan's Function Mapping with Inherited Types post of May 20, 2008 demonstrates the simplest approach, which is to create a single set of stored procedures for the base class and call them with wrapper functions in the SSDL file. A hitch in this process is that the wrapper functions are deleted each time you run the Update Database from Model operation.

Each wrapper changes the discriminator column value to conform to the level in the hierarchy, as discussed in the Re: Stored Procedures with Inheritance post of April 28, 2008 in the ADO.NET Entity Framework and LINQ to Entities (Prerelease) forum and David DeWitter's Entity Framework Stored Procedure Generation post of the same date..

Julie Lerman Discovers that EF Executes Stored Procs When Invoked, Not When Their Data is Needed

Her Command Execution of directly called ImportFunctions (stored procs) in Entity Framework post of May 20, 2008 explains the situation, which doesn't seem surprising to me.

ADO.NET Data Services to Add Replace Mode for Updates

In his Merge vs. Replace Semantics for Update Operations post of May 20, 2008, Pablo Castro announces that Astoria's current Merge update semantics will be complemented by a Replace option. Replace mode for the HTTP PUT method is required by the AtomPub spec.

The difference between the two modes is that Replace substitutes default property values for properties that aren't included in the uploaded message body's <Item> element, while Merge ignores missing properties. Missing links in Merge or Replace operations don't affect links on the server.

ADO.NET Team Offers Two New Entity Framework Web Casts

How Do I Get Started with the Entity Framework? (09:20)
In this introductory video, Alex James will show you how to build a simple Entity Data Model in a short amount of time.

How Do I Use the new EntityDataSource? (11:30)
In this introductory video Diego Vega will show you how to use the EntityDataSource in an ASP.NET Application.

SQL Server Compact 3.5 Runtime Bits Missing from VS 2008 SP1 Beta

SQL Server Compact 3.5 SP1 Beta and Synchronization Services for ADO.NET v1.0 SP1 Beta runtime bits didn't make it into the VS 2008 SP1 Beta package but you can download and install them from the preceding link.

Julie Lerman Takes on the Entity Framework Doubters

Julie posted this link to Bloglines citations of Danny's post in her Responses to Danny Simmons "Why Entity Framework" post of May 20, 2008.

Ironically, her post wasn't included in the Bloglines citation. (Several other cites in my Danny Simmons Answers the Frequently Asked Question: Why Use the Entity Framework? post were missing from Bloglines, too.)

Rob Conery Runs into a LINQ to SQL Corner with his Repository Model

He discovers "that if you set any Enumerable anything as a property, its Count property will be accessed when you load the parent object. This negates using any deferred loading for any POCOs, period." Yeah. That's run me nuts, too.

Update May 22, 2008: Scott Allen left a comment about Rob's preceding statement: "I'd say that requires more investigation. Doesn't sound correct." As it turns out, Scott did do some investigation and concluded that an IList<T> type change caused the overeager loading. See Rob's Not So Lazy MVC Storefront of 5/21/2008. 

Rob circumvents the problem by refactoring the MVC Storefront's Repository model, as described in his MVC Storefront: Intermission's Over, Made Some Changes post of May 19, 2008.

Update May 21, 2008: Rob clarifies the identity of his clients (the Microsoft ASP.NET team, the "community" and himself) in MVC Storefront: Client Progress Meeting of May 20, 2008, which details how the MVC Storefront project came to be at MIX 08 and his recent progress meeting with his boss, Shawn Burke.

Hopefully, it's time to go back to completing the code.

The SQL Server Data Service Team Breaks Their Silence

It's been a while since the last post from the SSDS folks. Soumitra Sengupta's What is going on at SQL Server Data Services of May 19, 2008 notes that SSDS is in the process of its second semi-monthly refresh after its introduction at MIX 08. Word on what new features, if any, the updates introduced will come some time after the refresh on May 20, 2008.

SSDS will be back in business by 9:00 AM on 5/21/2008.

SSDS documentation finally has been made public as the SQL Server Data Service Primer. The docs have some strange content, such as VS 2005 and .Net 3.0 being "recommended for Microsoft employees" to connect to SSDS. I recommend others use VS 2008 and .NET 3.5.

Update 5/21/2008: The SSDS team is Correcting an error in our documentation.

At MIX 07 the public beta was announced for July 2008. However, it's been pushed back two months to September 2008, according to Nigel Ellis's Introduction to New SQL Server Data Services: Web-Based Data Storage in a Cloud Web cast. I scheduled my Visual Studio Magazine article for the July issue to meet the original date; hopefully readers will be able to obtain a beta invitation if they aren't already "on-boarded" by July.

Mike Taulty Finds the Replacement for ADO.NET Data Services' DataWebKeyAttribute

Mike's ADO.NET Data Services and the Missing DataWebKeyAttribute post of May 19, 2008 explains that SP1 renamed it DataServicesKeyAttribute. This is consistent with the replacement of Web by Services in most class, method and property names.

If the Entity Framework back-end can't detect the table's primary key column you mus prefix the the class declaration with [DataServicesKey("ColumnName")] as mentioned in the ADO.Net Data Services Over LINQ to SQL? forum post.

Wally McClure Finds He Needs the Visual J# Redistributable to Get Meaningful Error Messages from ADO.NET Data Services

Strange, but apparently true, as Wally reports in ADO.NET Data Services in.NET 3.5 SP1 Beta1 of May 19, 2008. He promises a podcast about his Astoria experiences shortly.

Jon Skeet Gives Parallel LINQ a Workout with Nine Parallel LINQ (PLINQ) Mandelbrot Set Implementations

The Mandelbrot set is an ideal test bed for determining the efficiency of parallel processing algorithms and libraries. So Jon Skeet, C# MVP in the UK, decided to compare the performance of Parallel LINQ (PLINQ) with the Parallel Extensions (ParallelFx) with a variety of different approaches. The benchmarks are downloadable from his Mandelbrot revisited - benchmark edition post of May 18, 2008, which includes code samples and commentary.

Jon finds ParallelFx's ParallelForLoop implementation to have the best overall performance, but the PLINQ Unordered ParallelLinqInPlace approach wasn't far behind it.

1 comments:

Anonymous said...

"that if you set any Enumerable anything as a property, its Count property will be accessed when you load the parent object. This negates using any deferred loading for any POCOs, period." - I'd say that requires more investigation. Doesn't sound correct.