Sunday, August 17, 2008

LINQ and Entity Framework Posts for 8/13/2008+

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

••• Updated 8/17/2008 08:30 PDT: Explanation of ASP.NET Dynamic Data’s problem with EF and minor additions.

Updated 8/16/2008 18:15 PDT: Workaround for ASP.NET Dynamic Data’s "A property with name 'XX.Id' does not exist in metadata for entity type 'XX.XX.XXXX'” exception with the EF as the data source.

Updated 8/16/2008 12:30 PDT: Additions

Entity Framework (EF)

••• Asad Khan’s 49-page Entity Framework Supported Mapping Scenarios” white paper dated July 2008 carries the following summary:

This white paper enumerates the supported mapping scenarios in Entity
Framework. It also mentions important design considerations for store schema in
order to deal with advanced mapping scenarios.

Thanks to Julie Lerman for the heads-up on the white paper.

Kristofer Andersson’s Tools - Part 4 - Add-ins - Adding functionality to the Entity Framework EDMX designer post of 8/15/2008 describes EDMX Addin #1 to the Huagati DBML Tools: Renaming entity sets, entity types, properties, and navigation properties in EDMX (ADO.NET Entity Data Model) files. Kris says:

This is more or less similar to the DBML naming convention add-in but this one works with the Entity Framework designer instead of the LINQ-to-SQL designer. It updates the conceptual and mapping side and also comes with a new shiny options dialog allowing users to specify what naming rules to apply. The options dialog also has a “preview” field for each section at the bottom of the screen that shows what the outcome will be on classes/properties in the currently open EDMX file if using the selected settings.

The post contains screen captures of the addin being used with the HuagatiRes airline reservations database that’s described in my Comparison of Entity Framework and LINQ to SQL Projects Using a 120-Table Database post of July 13, 2008.

Julie Lerman proves EF doesn’t support projecting into known types or using custom properties from your partial classes in queries in her A few things you can't do with EF queries which you won't find out until runtime post of 8/15/2008.

Julie Lerman’s MSDN Forums post of 8/15/2008 announces she has three stars for 676 posts (count ‘em 676!) in the ADO.NET Entity Framework and LINQ to Entities (Pre-release) forum. Congrats!

Perhaps someone on the EF team will remove the “(Pre-Release)” suffix shortly. (But some consider v1 to be “pre-release” and v2 as the real “release” version.)

Roger Jennings finds SP1’s promised binding to many:one associations doesn’t work for upgraded projects in his Upgrading Databound Projects to Entity Framework V1 RTM Doesn’t Expose DataSource’s 1:Many Associations of 8/13/2008 (Updated 8/15/2008). The EF team is looking into the problem.

ADO.NET Data Services (Astoria)

••• Dare Obasanjo explains the essence of Representational State Transfer (REST) architectural style and its relationship to SOAP Web services in his Explaining REST to Damien Katz essay of 8/17/2008. Astoria provides a REST interface to EF or LINQ to SQL entities with AtomPub or JSON over HTTP as its wire protocol.

(Damien Katz is the creator of CouchDB, an Apache Incubator project for an open-source document-oriented database, which uses the “low REST” protocol. Low REST uses HTTP POST only; High REST uses GET, POST, and PUT verbs.)

Marcelo Lopez Ruiz’ Case Study for ADO.NET Data Services post of 8/15/2008 points to a Microsoft case study of Misys Healthcare Systems, which quotes Galen Murdock, President and CEO of partner Veracity Solutions:

ADO.NET Data Services gave us the ability to pull content dynamically from the server and also separate the markup from the data, which optimized performance.

Here’s the architectural diagram of the Misys/Veracity FreeNatal application from MisysVeracityCaseStudy.doc:

Hopefully, Marcelo delivered the last word about Silverlight and ADO.NET Data Services compatibility on 8/14/2008.

Gil Fink, a senior .NET developer and NET consultant for SRL Group (Israel), delivers part two of his ADO.NET Data Services tutorial: Building a .Net Client for ADO.NET Data Service (8/15/2008). Part 1, which covers the service side is ADO.NET Data Services Introduction of 8/10/2008.

Mike Flasko points to a new series of "How Do I Videos" videos about ADO.NET Data services. The first two members are here:

SQL Server Data Services (SSDS)

••• Sam Johnston reports in his “Dell Denied: 'Cloud Computing' both desciptive and generic” post of of 8/15/2008 that the US Patent and Trademark Office (USPTO) have denied Dell, Inc.’s application for a trademark (actually a servicemark) on “Cloud Computing.” The application was the topic of my Dell Attempts to Purloin “Cloud Computing” Trademark post of 8/3/2008. Sam says:

First [USPTO] argued that 'the applied-for mark merely describes a feature and characteristic of applicant’s services'. A mark is merely descriptive if it describes an ingredient, quality, characteristic, function, feature, purpose or use of the specified services. That is, 'cloud computing' simply describes a type of computing in the same way that 'yellow bananas' describes a (common) type of banana.

Furthermore, they have declared 'cloud computing' generic, in that it is 'incapable of functioning as a source-identifier for applicant’s services'. This makes sense given that few of us think 'Dell' when we think of 'cloud computing', even in this context.

Somitra Sengupta’s On going quiet and transparency in the design process post of 8/15/2008 explains why the SSDS team is reticent to adopt the ADO.NET Data Services and Entity Framework teams’ transparent design model until after PDC 2008. (In return, I’ll stop bugging them.)

ASP.NET Dynamic Data (DD)

••• Scott Hunter’s Workaround for Dynamic Data Entity Framework Posted post of 8/16/2008 explains the problem as follows:

The main issue is a slight mis-match in the names that Dynamic Data looks for in Entity Framework and the names that Entity Framework is actually exposing. When this problem occurs an error that looks like "A property with name 'XX.Id' does not exist in metadata for entity type 'XX.XX.XXXX'".

Luckily we made the data model providers which are classes that look at data model and tell Dynamic Data what the tables, columns, names, etc are a extensible system. This means we can distribute a replacement data model provider that solves the issue I mentioned above.

The moral of this story: Test your product with all likely data sources, rather than just today’s favored data source (LINQ to SQL).

Scott Hunter of the DD Team posted to the Dynamic Data Entity Framework Workaround thread 0f 8/16/2008 a message with a link to the workaround in CodePlex for the "A property with name 'XX.Id' does not exist in metadata for entity type 'XX.XX.XXXX'” exception with the Entity Framework as a data source.

Marcin Dobosz posted this response to DD’s problem with EF v1:

We have a solution that is pending testing that we will make available as soon as possible. We should have more details about this on Monday.

on 8/16/2008 in the ASP.NET Forum’s Dynamic Data SP1 chokes on Northwind and AdventureWorks using ADO.Net Entity Data Model thread.

Roger JenningsSerious Fail of ASP.NET Dynamic Data SP1 with Entity Framework v1 RTM Data Source of 8/14/2008 describes known blocking bug when using ASP.NET Dynamic Data with EF v1 RTM in VS 2008 SP1. (See above updates.)

LINQ to SQL

No posts found

LINQ to Objects, XML, et al.

••• Bart De Smet‘s Folding left, right and the LINQ aggregation operator post of 8/17/2008 provides insight into LINQ’s Aggregate operator from functional programming’s fold viewpoint.

Beth Massi interviews Yang Xiao, a tester on the VB IDE team, about the XML Schema Explorer in VS 2008 SP1: Channel 9 Interview: XML Schema Explorer in Visual Studio 2008 SP1.

Bart De Smet continues an extension of his “Custom LINQ Providers” session at Tech•Ed South Africa with The Most Funny Interface Of The Year … IQueryable<T>, an explanation of why IQueryable<T> is “such a special specimen.” See below for resource links.

John Papa reviews Bart De Smet’s LINQ to Active Directory implementation in LINQ to AD – Grade B of 8/15/2008 and makes a suggestion for improvement.

The XML Team announces that the XML Schema Explorer is included with SP1 in New XSD Functionality shipped in Visual Studio 2008 SP1 RTM of 8/14/2008.

Bart De Smet digs into issues of string equality in Expression Tree Normalization – How Many Ways To Say “String == String”? of 8/13/2008, which expands on his “Custom LINQ Providers” session at Tech•Ed South Africa. Bart’s TechEd 2008 South Africa Demo Resources post of 8/9/2008 provides links to downloadable files and other resources for his presentations.

Visual Studio 2008 Service Pack 1 (General)

••• Roger Jennings updated the two posts below on 8/17/2008 after finding the “An error occurred while performing the drop” message disappeared when recreating the data sources a second time. However, data sources based on EntityCollections (one:many associations) still throw errors when attempting to set the BindingSource.DataMember with code and the DataMember property value appears as None in the BindingSource properties sheet.

Roger Jennings updated The Joys of Installing Visual Studio 2008 Service Pack 1 with another problem (Upgrading Databound Projects to Entity Framework V1 RTM Doesn’t Expose DataSource’s 1:Many Associations in the Entity Framework section) on 8/13/2008.

Steve Lasker explains Why doesn't Visual Studio 2008 SP1 installer update SQL Server Compact 3.5 for Devices? (8/13/2008).

SQL Server Compact 3.5 and Sync Services

From Liam Cavanaugh’s Now Available - SyncToy 2.0 File Synchronization post of August 14, 2008:

SyncToy 2.0 for Windows is available as a free download and is an easy to use, customizable application that helps you copy, move, rename, and delete files between folders and computers.

SyncToy is powered by Microsoft Sync Framework and is yet another example of how Sync Framework helps to create end-to-end solution for enabling synchronization of any content or data.

In my view, Sync Toy is a simple counterpart to Live Mesh’s synchronization services that developers can customize for their own purposes.

Steve Lasker announces SQL Server Compact 3.5 SP1 available for Win CE 5.0 and 6.0 Platform Builder (8/14/2008).

The Microsoft Sync Framework Group published 3 (more) New Sync Samples - Sync 101 for Sync Framework SDK v1.0 on 8/14/2008.

Miscellaneous (WPF, WCF, Silverlight, etc.)

Silverlight guru Matt Berseth demonstrates Custom Sort Icons with Silverlight 2's DataGrid Control and provides source code, too (8/14/2008.)

Rudi Grobler published Introduction to the WPF DataGrid, a detailed tutorial on the WPF DataGrid CTP to the Code Project on 8/12/2008.

Varsha Mahadevan posted the WPF DataGrid CTP to Windows Presentation Foundation (WPF) with links to WPFToolkit_Binaries.zip and WPFToolkit_SourceAndBinaries.zip on 8/11/2008.

Thursday, August 14, 2008

Upgrading Databound Projects to Entity Framework V1 RTM Doesn’t Expose DataSource’s 1:Many Associations

If you start your WinForm project with bound master-child[-grandchild] controls in a new project created with Visual Studio 2008 SP1 and using Entity Framework RTM as its data source, the nodes representing hierarchical 1:Many associations behave identically to those for typed DataSet and LINQ to LINQ to SQL data sources.

Update 8/17/2008: The “An error occurred while performing the drop” message disappeared when recreating the data sources a second time. However, data sources based on EntityCollections (one:many associations) still throw errors when attempting to set the BindingSource.DataMember with code and the DataMember property value choice appears as None in the BindingSource properties sheet.

Here’s a capture of the properties window with the missing DataMember property value choice for the ordersBindingSource as the DataSource property value of the order_DetailsBindingSource:

 

The DataSource code inserts the Order_Details DataMember value; you can’t select it or, in some cases, set it in code. For example,

ordersBindingSource = customerBindingSource;
ordersBindingSource.DataMember = "Orders";

throws a "Cannot bind to the property or column Address on the DataSource. Parameter name: dataMember" exception.

Updated 8/14/2008: Runtime exception details added.

For example, when you add to the Data Sources window a Customer EntitySet persisted to the Northwind.Customers table, you can drag the Customer.Orders node to the form to generate an orderBindingSource and bound orderDataGridView. In this case, orderBindingSource.DataSource = customerBindingSource and orderBindingSource.DataMember = “Orders”.

Links between the Customer EntitySet and Orders EntityCollection, BindingSources and DataGridViews are shown here in VS 2008 SP1 (Click image for full-size screen capture):

Similarly, dragging the Customer.Order.Order_Details node to the form generates order_DetailBindingSource.DataSource = orderBindingSource and order_DetailBindingSource.DataMember = “Order_Details”. Binding the two BindingSources to the associated EntityCollection synchronizes the orderDataGridView to the selected Customer entity and the order_DetailsDataGridView to the selected Order entity.

Problems with an Upgraded WinForms Project

Upgrading a pre-VS 2008 SP1 project to take advantage of EF v1’s new databinding enhancements by replacing the *.edmx file and its *.designer.cs or .vb partial class file with a new one requires you to:

  1. Delete the existing *.edmx file and its related files
  2. Delete the now-empty data sources from the Data Sources window
  3. Create a new *.edmx file in the EDM Designer
  4. Change the EDM partial class namespace from *Model to ProjectName
  5. Add new data sources to the Data Sources window
  6. Create new binding sources for child [and grandchild] DataGridView controls by dragging EntityCollection nodes to the form in design mode

Attempting step 6 for, as an example, the Customer.Orders EntityCollection, throws the following exception:

as noted in an update to my recent The Joys of Installing Visual Studio 2008 Service Pack 1 post.

Update 8/15/2008: Attempting to set the BindingSource at runtime with the following code:

order_DetailBindingSource = orderBindingSource;            order_DetailBindingSource.DataMember = "Order_Details";

throws a “The method or operation is not implemented” exception at runtime.

Most experienced .NET developers tend to avoid drag-and-drop databinding like the plague, but it’s handy for hooking up lightweight EntityCollections guaranteed to have a relatively few rows, such as line items of sales orders, invoices, or purchase orders. Line items must all be visible to create a meaningful UI for the user, while specific orders or groups of orders for a customer can be downloaded as required.

Having to perform major surgery on existing applications to take advantage of a new and needed feature is painful.

Serious Fail of ASP.NET Dynamic Data SP1 with Entity Framework v1 RTM Data Source

Update 8/18/2008: Scott Hunter of the DD Team posted to the Dynamic Data Entity Framework Workaround thread 0f 8/16/2008 a message with a link to the workaround in CodePlex for the "A property with name 'XX.Id' does not exist in metadata for entity type 'XX.XX.XXXX'” exception with the Entity Framework as a data source.

For more information about the workaround, see Workaround for Dynamic Data Entity Framework Posted post of 8/16/2008.

Apparently the DD team tested their SP1 release only with LINQ to SQL as the data source. This is surprising when you consider the emphasis the Data Programmability group is placing on Entity Framework.

I’ve tested Microsoft.Web.DynamicData.dll (the replacement for System.Web.DynamicData.dll) and the revised RegisterContext() method. It fixes the problem for me. The updated version of the DynamicDataWebApp project has been incorporated in a replacement for the VS0808RJ.zip file that should be posted at http://code.visualstudiomagazine.com/vs0808rj.zip shortly. The DynamicDataWebSite file-system project uses LINQ to SQL as its data source, so it wasn’t affected by the DD team’s gaffe.

In the meantime, you can download the updated code from SkyDrive.

Original Content Starts Here

A reader of my “Generate Web Sites Automatically” cover story for the August 2008 issue of Visual Studio Magazine reported today that the accompanying sample code threw a runtime exception under VS 2008 SP1 when clicking the View Order_Details link of the Orders list page shown below (click image for a full-size capture):

The “A property with the name ‘Order.OrderID’ does not exist in metadata for entity type ‘NorthwindModel.Order_Detail’” runtime error appears as follows (click for full size):

This problem was reported on August 13, 2008 in Dynamic Data SP1 chokes on Northwind and AdventureWorks using ADO.Net Entity Data Model thread or the ASP.NET ASP.NET Dynamic Data forum. According to David Ebbo’s reply on the same date:

There is indeed an issue with the Entity Data Source that is causing this. Here it is described by someone from the Entities team:

"Currently for a (1 : 0..1) relationship, we expose references to the “1” end but we don’t expose the references to the “0..1” end. For ex: consider something like “Person”->”PersonDetails” with a (1 : 0..1) relationship between them:

There will be a property descriptor “Person” on “PersonDetails” entity. However there’ll be no property descriptor called “PersonDetails” on “Person” entity."

We'll see if there are some possible workarounds.  BTW, you mention that you also see this with Northwind.  Specifically, which Northwind table are you seeing this on?

It appears to me that the problem differs from the description above. The multiplicity of the Order:Order_Details relationship is 1:*, and there is no reason for an attempt to read the Order_Details.Order.OrderID value from the associated (1:0..1) EntityReference.

If there aren’t “some possible workarounds” available immediately, this will be a serious blow to the Data Programmability group’s attempt to position the Entity Framework as the preferred data source for new programming frameworks, such as ADO.NET Data Services (Astoria).

In the event there’s no prospect for a timely workaround, I’ll change the data source for the sample projects from Entity Framework to LINQ to SQL and update the sample code accordingly.

Wednesday, August 13, 2008

The Joys of Installing Visual Studio 2008 Service Pack 1

The following is a better location than MSDN Subscriptions from which to download Visual Studio 2008 Service Pack 1 (SP1) and .NET Framework 3.5 SP1 Downloads.

Updated 8/12/2008: Clarification of MSDN Library download and saga of the failure of my initial upgrade and 8/13/2008: “An error occurred while performing the drop” error message added.

Problem 1: You’ll probably encounter the following Microsoft Visual Studio Patch Removal Tool message when you attempt to run the installer:

Here’s a link to the Visual Studio 2008 Service Pack 1 (SP1) Readme.

Update 8/12/2008: You need about 3.7 GB of free drive space to run the SP1 installer.

Problem 2: My first couple of attempts to download and install the “Microsoft Visual Studio Patch removal tool” incurred a not-found message, which others had apparently encountered (see the Visual Studio 2008 SP1 RC: Patch Removal Tool link doesn't work message in the Connect forum.)

Ultimately, I was able to download and run the Visual Studio 2008 Service Pack Preparation Tool shown here:

Downloading required about 13 minutes on a ~3 mbps DSL connection; installation required about 25 minutes on a moderately fast machine and 45 minutes on an older Dell server.

Problem 3: You’ll need the original media from which you installed VS 2008. (This reminds me of Office 2000 + service packs and updates.)

Problem 4: Online Help files are a separate 2.15 GB download. Click the MSDN Library for Visual Studio 2008 Service Pack 1 (x86, x64 WoW) - DVD (English) link in the “Top Subscriber Downloads” of the MSDN Subscriptions Page. (The link in the Readme’s section “2.1.7 Visual Studio 2008 SP1 will not install MSDN Library for Visual Studio 2008 SP1 during Setup” returns a 404.)

Update 8/12/2008: Help download point corrected. It appears that the Visual Studio team isn’t proud of their updated VS 2008 SP1 help file; they’re certainly doing their best to hide its download point. There should be a link to download the MSDN Library for SP1 on the main download page.

Problem 5: According to Amy Dullard’s Silverlight Tools Must be Updated After Installing Visual Studio 2008 SP1 blog post of August 11, 2008, you’ll also need to update your Silverlight 2 Beta 2 toolkit from http://go.microsoft.com/fwlink/?LinkID=120032.

Update 8/12/2008: Problem 6: My initial upgrade to my primary development machine failed, despite the fact that the install log said that the upgrade succeeded. .NET Framework showed SP1 in Programs and Features.

The first symptom of the failure I found was an error when I attempted to use the Entity Framework’s new data-binding feature. When attempting to drag the Customers.Orders node from the Data Source window to a form to add and ordersBindingSource component and ordersDataGridView control I received the following error message:

Failed to get properties of data source ‘Orders’ because of the following error:

Requested Operation is not allowed when the owner of this RelatedEnd is null. RelatedEnd objects that were created with the default constructor should only be used as a container during serialization.

Another indicator of a problem is Visual Studio 2008 SP1 Beta 1 as the product name in the Help | About dialog.

Update 8/13/2008: Problem 7: After upgrading a complex master/details/subdetails form created with VS 2008 SP1 Beta to SP1 RTM, which was no walk in the park, attempts to replace a Beta BindingSource/DataGridView by dragging the related association node to a Windows form throws this design-mode exception:

The help topic for this exception says:

When dragging items from the Data Sources window onto controls, the items must be valid drop sources for the control. For example, you cannot drag a TextBox onto a Button.

Clearly a form is a valid drop source for the BindingSource/DataGridView combination.

Note: The preceding error message is the same as that for problem 6 except for the first paragraph.

Update: Guy Burstein’s .Net Framework 3.5 SP1 and Visual Studio 2008 SP1 are Available! post of August 11, 2008 has links to many SP1-related resources.

LINQ and Entity Framework Posts for 8/12/2008

Note: Due to the volume of VS 2008 SP1 items, this post covers only August 12, 2008 content in an abbreviated format.

Entity Framework v1

Alex JamesStructural Annotations - One Pager explains changes in store for SSDL and CSDL schema annotations to support other EF applications, such as Reporting Services. Alex asks at the conclusion, “Do you think you will find a use for Structured Annotations?”

Kris Andersson continues his Designing an airline passenger reservation system series with Application Architecture - Part 5a - Data Access Layer - A closer look at ADO.NET Entity Framework, which describes his attempt to create a Entity Data Model from an SQL Server database with 1000+ tables and 2000+ associations. After six hours he gave up. Kris promises:

The next article in this series (5b) will re-visit the performance comparison between EF and Linq to SQL that Roger Jennings performed on the beta. I am hoping that the beta version was slowed down by debug code and that the RTM version will be faster / have less overhead.

Julie Lerman analyzes the ADO.NET Team’s What's new in the VS 2008 SP1? post of 8/11/2008 in her Entity Framework changes between SP1 Beta and RTM post.

Jeff Derstadt supplies a list of Entity Framework RTM Breaking Changes classified as Provider Changes, Entity Services Changes, Mapping and Metadata Changes, EntityDataSource Changes and Tools Changes categories.

Danny Simmons has updated his Entity Framework FAQ for SP1 in EF FAQ updated. So far, I haven’t found any documentation or other information about the new data binding features.

Julie Lerman describes the strangely named EF: GetRelationTypeExpensiveWay method, announces two new sites to support her forthcoming book (LearnEntityFramework.com and ProgrammingEntityFramework.com), and discusses her most recent 14-page Article: Data Access Options in Visual Studio 2008 in the September/October 2008 issue of CoDe Magazine. (The article’s available in print but isn’t on line yet.)

ADO.NET Data Services (Astoria)

Guy Burstein shows how easy it is to add a Service Reference to an ADO.NET Data Services back end in VS 2008 SP1: Add Reference to ADO.Net Data Service and WCF Service Contract changes in WCF Service Contract Refactoring affects Configuration File in VS2008 SP1.

Mike Flasko describes the maddening issue of the Silverlight Client Library’s incompatibility with ADO.NET Data Services SP1 in Compat Note: Silverlight Beta 2 Client & .NET Framework 3.5 SP1 Server Components. If you install VS 2008 SP1, your out of luck when attempting to use a Silverlight 2 front end with Astoria SP1.

Marcelo Lopez Ruiz explains how the DataServiceContext’s IgnoreMissingProperties property immunizes Astoria projects from breaking when the server implements a new property in Ignoring server properties.

SQL Server Data Services

DRD’s Performance of Soap compared to Rest post in the SQL Server Data Services (SSDS) - Getting Started forum confirms an approximate 2:1 difference in SOAP and REST upload performance that I reported in my Updated SQL Server Data Services (SSDS) Test Harness: Northwind REST and SOAP Uploads post of

Mike Amundsen has started an SSDS FriendFeed Room for “Conversations around SQL Server Data Services.” It’s public, so anyone can join.

ASP.NET Dynamic Data

No articles found.

LINQ to SQL

Matt Manela provides the code for “generic methods for inserting and updating a detached entity into a database using LINQ to SQL” in Generic Insert and Update for LINQ To SQL.

Robert Cain promises a future post to show how to access SQL Server Compact 3.5 from LINQ to SQL in Getting Started with SQL Server Compact Edition 3.5. (LINQ to SQL is a far more rational choice as an O/RM for SSCE than Entity Framework.)

Update 8/13/2008: Rosor Demonstrates a Heterogeneous Join in LINQ with VB.NET: Join SQL with a CSV file or List of objects.

LINQ to Objects, XML, et al.

No articles found.

Miscellaneous

Steve Lasker answers the question: Why does VS 2008 SP1 not include SQL Server Compact 3.5 SP1 64bit?.

Update 8/13/2008: Steve updates his answer with Why doesn't Visual Studio 2008 SP1 installer update SQL Server Compact 3.5 for Devices?

Liam Cavanagh describes 2 New Sync Samples - Download Only & Adapter Builder for Sync Services for ADO.NET v2.

Tuesday, August 12, 2008

LINQ and Entity Framework Posts for 8/11/2008

Note: Due to the volume of VS 2008 SP1 items, this post covers only August 11, 2008 content in an abbreviated format.

Entity Framework v1

Tim Mallalieu’s A Brief History in ENTITIES (... or what the Heck is this EF THing?) - part I essay discusses “why we built the EF and the EDM, what we think it is and where we think it is going.”

The Entity Framework Team’s ADO.NET Entity Framework & LINQ to Relational Data Code Gallery has an UPDATED Entity Framework Toolkits & Extensions WIKI.

ADO.NET Data Services (Astoria)

Pablo Castro’s Coming from under the rocks just to celebrate for a bit explains what’s coming to Astoria post-SP1, including “Astoria Offline” and alignment of alignment with SQL Server Data Services (SSDS) in vNext.

Raju Phani gives the location of Astoria documentation (System.Data.Services.Client) and promises that whitepapers are coming soon in MSDN Docs for ADO.NET Data Services RTM and provides C# examples for Query Interceptors and Change Interceptors in Code Snippets for Common Tasks in Ado.net Data Services.

Marcelo Lopez Ruiz gives brief explanations of the classes in the System.Data.Services namespace.

Mike Flasko summarizes SP1 changes and enhancements to Astoria in RTM is here!

SQL Server Data Services

Senkwe Chanda asks the SSDS team “Will client applications that make SSDS requests be able to do so securely (directly to my Containers) without having to go through a central server owned by the app developer?” in his Authentication for client applications accessing SSDS resources thread starter in the SQL Server Data Services (SSDS) - Getting Started forum. So far, there’s been a response from Mike Amundsen, but not the SSDS folks.

ASP.NET Dynamic Data

Maíra Wenzel’s Dynamic Data documentation is released! provides links to the official ASP.NET Dynamic Data documentation.

LINQ to SQL

Alvin Yong discusses “propagating LINQ entities from the DAL to the UI and back, using the Repository pattern to handle entities and my current favourite approach: using DTOs” in LINQ for n-Tier Architecture Part 2. LINQ for n-Tier Architecture (5/27/2008) was part 1.

Dinesh Kulkarni describes SP1’s substantial (~30%) performance improvements for LINQ to Objects and LINQ to SQL queries in .NET Framework 3.5 SP1: LINQ perf improvements (LINQ to Objects and LINQ to SQL).

LINQ to Objects, XML, et al.

The domain.net.team describes a breaking change to Cast<T> in Undocumented Linq! .NET 3.5 SP1 Gold Forgot to Mention these Critical Changes that might Break your Code.

Miscellaneous

Anthony Carrabino provides and extensive feature list for SQL Server 2008 Express, with Tools and with Advanced features in SQL Server 2008 Express now available for download.

Zain Naboulsi fully documents his Defy Occasionally Connected Challenges with Smart Client Applications Heroes Happen Here Launch Events demo with a step-by-step tutorial and sample code in Creating and Using Synchronization Services with Visual Studio 2008.

Matt Berseth shows you how to conserve column space with Angled Column Headers with Silverlight 2's DataGrid.

Guy Burstein announces the availability of the Training Kit for VS 2008 SP1 and .Net Framework 3.5 SP1

Sunday, August 10, 2008

LINQ and Entity Framework Posts for 8/8/2008+

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

Shawn Wildermuth Attacks the Reality of Data-Last Design in the Enterprise

Shawn’s Rigidity in Data Design post of August 9, 2008 is a thought-provoking essay about the validity of the ALT.NET members and Domain-Driven Development adherents contention that “that data is a top-down or at worse, bottom up design problem” and the assumption that greenfield persistence (database) schema are de riguer for most data-intensive development projects.

Shawn takes the position, with which I agree, that most data-driven development projects start with an existing database schema and a substantial amount of historical data. I estimate that nine out of ten projects that I’ve completed in the past 20 years worked extensively with existing business data on mainframes, minicomputers, and mid-range UNIX servers.

Shawn concludes:

No *rule* applies in all situations. I laud the ALT.NET guys for trying to inject better skills and tools into the process, I just rail against the ferocity of zealotry that comes in some of the message. When enterprise developers hear this, they just tune it out instead of taking what helps them and leaving the rest.

Added: August 10, 2008

Steve Naughton Adds Custom Row Rollover and Row Click Behavior to ASP.NET Dynamic Data Grid Views

His Customising GridView for Row Rollover and Click in Dynamic Data post of August 9, 2008 adds:

  • Background color change with mouse rollover
  • Row click navigation (e.g., to details view)
  • Row double-click navigation (e.g., to edit view)

to GridView controls in ASP.NET Dynamic Data projects. Steve’s prodigious output of code for customizing ASP.NET Dynamic Data projects goes far beyond what the Microsoft team has provided in documentation and blog posts so far.

Bart De Smet Offers LINQ Resources from Three of his Four Tech*Ed South Africa 2008 Sessions

Bart’s TechEd 2008 South Africa Demo Resources post of August 9, 2008 provide downloadable files and other resources from his two LINQ-related presentation and an additional Tech*Ed South Africa 2008 session:

  • DEV 305 – C# 3.0 and LINQ Inside Out
  • DEV 303 – Parallel Extensions to the .NET Framework
  • DEV 304 – Writing Custom LINQ Providers
  • MGT 301 – Next-Generation Manageability – Windows PowerShell and MMC 3.0

VS 2008 SP1 RTM Scheduled for Monday, August 11, 2008

Visual Studio 2008 Service Pack 1 will be available for download from the MSDN Subscriptions page "after August 11, 2008.”

If you have VS 2008 installed, don’t run SQL Server 2008 setup until after you install VS 2008 SP1 RTM bits.

For more information, see my VS 2008 SP1 RTM Scheduled for Monday, August 11, 2008 post of August 8, 2008.

Bill McCarthy Casts a List(Of DerivedClass) to List(Of BaseClass) with Generic Variance via an Extension Method

Bill starts his Generic variance and List(Of T) post of August 8, 2008 with:

Have you ever wanted to cast a List(Of Customer) to a List(Of BusinessBase), where Customer Inherits BusinessBase, only to find that you can't... well you can ;)

But his extension method uses reflection do it. (His post is an extension to his Inside Arrays article for in Visual Basic Magazine’s July 2008 issue.

For more information about Generic Variance see Variance in Generic Types (C# Programming Guide) article, Paul Vick’s A little update on VB10 thinking... post that says Generic Variance is on VB vNext’s radar, and Eric Lippert’s 11-part Covariance and Contravariance in C# blog series.

Don Kiely Describes Why Web Sites Running in Medium Trust Can’t Use Entity Framework v1

Don’s “Dynamic Data with the Entity Framework in Medium Trust” article for the ASP.NET Newsletter August 8, 2008 issue’s “Secure ASP.NET” column publicizes an ASP.NET Dynamic Data forum thread: Should Dynamic Data (Entity Framework model) work in medium trust?

The upshot of the thread is that the EntityDesignerBuildProvider throws exceptions the when run in medium trust on hosted Web sites. According to the Entity Framework team’s Diego Vega:

    1. The problem only affects Web Sites. Web Applications are not affected.
    2. Web Sites precompiled in full-trust and deployed to partial-trust apparently work.

Don and Diego suggest the same workarounds.

Thanks to Julie Lerman for the heads-up.

Ardenkantur Recounts Issues Using Entity Framework with Jaroslaw Kowalski’s Oracle Data Provider

His My Adventures with Entity Framework and Oracle post of August 8, 2008 describes issues with mixed-case versus upper-case table and column names, inability to specify column names in the EDMX file’s SSDL (storage) section instead of the mapping layer (MSL),  and use of ROWNUM clauses in Skip and Take operations.

The post is based on Jaroslaw’s EFOracleProvider described in his Sample Entity Framework Provider for Oracle post and available for download from under the Microsoft Public License (MS-PL), which isn’t intended for production use. However, users of commercial EF-enabled Oracle Managed Data Providers should watch out for the the problems Ardenkantur encountered in his pre-RTM test.

Pete Montgomery Demonstrates Caching the Result of LINQ Queries

In Caching the results of LINQ queries of August 8, 2008, Pete describes how to cache the result of LINQ queries that will will:

    • work for any LINQ query (over objects, XML, SQL, Entities…)
    • work for anonymous type projections, as well as business entities
    • be statically type safe (no casting required)
    • deal transparently with cache key creation
    • look syntactically like a custom query operator

He generates the unique cache key from the query expression.

Although Pete’s technique targets ASP.NET’s System.Web.Caching.Cache class, he says the approach “can be used by any .NET application or library.”

Note: Ayende Rahien (Oren Eini) has just completed a series of blog posts on distributed hash tables (DHT). His Patterns for using Distributed Hash Tables: Conclusion post of August 9, 2008 has links to the preceding eight episodes. If you’re interested in object caching in .NET, this series is a must-read.

Billy McCafferty Releases S#arp Architecture v0.7.3 Supporting ASP.NET MVC Preview 4 and NHibernate 2.0 CR 1

Billy’s S#arp Architecture: a new home, upgrades and a logo! post of August 8, 2008 announces the release of the latest version of S#arp Architecture: ASP.NET MVC with NHibernate (0.7.3), which supports ASP.NET MVC Preview 4 and NHibernate 2.0 CR1, and the formation of a S#arp Architecture Discussion Group on Google Groups.

He describes his new framework, which carries a GNU General Public License v3 license, as follows:

Pronounced "Sharp Architecture," this is a solid architectural foundation for rapidly building maintainable web applications leveraging the ASP.NET MVC framework with NHibernate. The primary advantage to be sought in using any architectural framework is to decrease the code one has to write while increasing the quality of the end product. A framework should enable developers to spend little time on infrastructure details while allowing them to focus their attentions on the domain and user experience. Accordingly, S#arp Architecture adheres to the following key principles:

  • Focused on Domain Driven Design
  • Loosely Coupled
  • Preconfigured Infrastructure
  • Open Ended Presentation

The overall goal of this is to allow developers to worry less about application "plumbing" and to spend most of their time on adding value for the client by focusing on the business logic and developing a rich user experience.

Billy is the author of NHibernate Best Practices with ASP.NET, 1.2nd Ed., which is required reading for anyone developing data-driven ASP.NET projects, regardless of whether you’re using or plan to use NHibernate, Entity Framework, LLBLGen Pro, or any other .NET Object/Relational Management O/RM tool.

Kingsley Idehen: OpenLink Software Publishes White Paper about LINQ to RDF

Kingsley describes Carl Blakeley’s LINQ To RDF: Exploiting the RDF based Linked Data Web using .NET via LINQ white paper of July 31, 2008 in his .NET, LINQ, and RDF based Linked Data (Update 2) post of August 8, 2008:

The paper offers an overview of LINQ to RDF, plus enhancements we've contributed to the project (available in LinqToRdf v0.8.). The paper includes real-world examples that tap into a MusicBrainz powered Linked Data Space, the Music Ontology, the Virtuoso RDF Quad Store, Virtuoso Sponger Middleware, and our RDfization Cartridges for Musicbrainz.

OpenLink Software is the publisher of Virtuoso, “an innovative Universal Server platform that delivers an enterprise level Data Integration and Management solution for SQL, RDF, XML, Web Services, and Business Processes.”

Amirthalingam Prasanna Offers a Introductory Guide to ADO.NET Data Services

His “Creating Service-Orientated Data-Access Layers” article of Redgate Software’s Simple-Talk newsletter of July 30, 2008 is yet another tour of ADO.NET Data Services but, unlike many other Astoria articles and blogs, it includes the basic details of query interceptors and change inteceptors for implementing role-based security.

Thursday, August 07, 2008

VS 2008 SP1 RTM Scheduled for Monday, August 11, 2008

According to the MSDN Subscriptions page’s “SQL Server 2008 RTM Available for Download” topic, Visual Studio 2008 Service Pack 1 will be available for download from the page "after August 11, 2008.”

Note: My assumption is that the author of this sentence meant “on August 11, 2008 and thereafter,” not “sometime after August 11, 2008.”

The SQL Server 2008 RTM Release Note author undoubtedly anticipated that VS 2008 SP1 would RTM on August 4, as Danny Simmons did when he recorded his Daniel Simmons on Entity Framework v1! interview that .NET Rocks! released as Show #365 on August 5.

Update 8/8/2008: Danny explained the premature RTM date in his EF v1 (delivered by VS 2008/.net 3.5 SP1) is... almost... here. (And the .Net Rocks podcast announcing it is already here.) post of August 5.

For more information on installing SQL Server 2008 with or without VS 2008 SP1, see Euan Garden’s SQL Server 2008 Installation Confusion, VS 2008 Sp1 and NetFx 3.5 Sp1 post of August 7, 2008.

From the Semi-Non Sequitur Department 8/9/2008: Software Development Times published .NET 3.5 SP1 to ship this summer by David Worthington on August 8, 2008.

LINQ and Entity Framework Posts for 8/4/2008+

Mike Ormond’s Three-Part Series about Securing Entities in ASP.NET Dynamic Data

Mike posted on August 7, 2008 the following three episodes about controlling the visibility of pages and their underlying tables:

Surprisingly, Mike uses VB code for his demos.

Added: August 7, 2008

Guy Burstein Offers Links to a Bevy of Useful SQL Server 2008 Resources

His SQL Server 2008 Resources post of August 7, 2008 includes links to SQL Server 2008 downloads, What’s New summaries, forums, Jumpstart materials, learning resources, database samples, and Guy’s pre-RTM posts on SQL Server 2008.

Added: August 7, 2008

Eric Nelson Draws LINQ Concept Map with IHMC’s Cmap Client and Server

The Institute for Human and Machine Cognition (IHMC), a not-for-profit research institute of the Florida University System, has sponsored the development of Concept maps and implementation of Cmap clients and servers for multiple operating sytems as the IHMC Cmap Tools. Eric Nelson spent five minutes creating a Cmap featured in his My first concept map – LINQ overview post of August 7, 2008.

Added: August 7, 2008

Steve Lasker Announces Release of 32-bit and 64-bit SQL Server Compact 3.5 SP1

Steve’s SQL Server Compact 3.5 SP1 Released post of August 7, 2008 notes that SSC SP1 offers the following new features:

  • ADO.NET Entity Framework provider. The Entity Framework enables you to work with data in the form of domain-specific objects and properties, such as customers and customer addresses, without having to concern yourself with the underlying database tables and columns where this data is stored.
    • Support for the ADO.NET Entity Framework allows you to create flexible, strongly typed queries against the Entity Framework object context by using LINQ expressions and the LINQ standard query operators directly from the development environment.
  • Case-sensitive collations for those C# folks that were allowed into the database <g>
  • Native 64bit support. No more locking your apps to WoW mode or Target = X86. And yes, we support a single version of your app that can privately deploy Compact 32 and 64 so your customers don't have to figure out whether they're running 32 or 64bit operating systems.

Update: August 8, 2008: SSC SP1 documentation is now available at SQL Server Compact 3.5 SP1 Books Online and Samples.

Added: August 7, 2008

Steve Naughton Adds Another Advanced FieldTemplate for ASP.NET Dynamic Data

His Dynamic Data and Field Templates - An Advanced FieldTemplate with a GridView post of August 7, 2008 describes the fifth advanced FieldTemplate for ASP.NET Dynamic Data, which embeds a GridView in a FormView control to enable use of the AJAX Toolkit’s Tab control.

Added: August 7, 2008

Julie Lerman Explains the Advantages of Using the GetObjectByKey() Method Instead of Retrieving the Object with a Query

Julie’s GetObjectbyKey in E.F. vs. Querying for a single entity post of August 6, 2008 points out that using the GetObjectByKey() or TryGetObjectByKey() method will return a reference to the entity, if it’s present in the cache, or query the persistence store if it’s not. On the other hand, querying for the entity always involves a roundtrip to the store.

Added: August 7, 2008

David Robinson Wants Guidance on Future SSDS Client Demo Projects

In his What kind of examples would be helpful? post of August 6, 2008, Dave wants to know:

  • Would you rather see code snippets or a fully working application?
  • Would you rather see a console app? WinForm? ASP.Net? WPF? Silverlight?
  • What type of app?
  • What are the challenging scenarios that you are facing that you would like a reference application to help you solve?

I’d rather see fully working applications as WinForm and WebForm apps, as I noted in a comment to his post. Samples dedicate to new features implemented in the most recent Sprint would be useful, too.

Added: August 7, 2008

Hilton Giesenow Explains How to Use Enumerations with LINQ to SQL

His Using Enums With LINQ To SQL post of August 6, 2008 gives you the details.

Added: August 7, 2008

Julie Lerman: Deciding Whether to Use Entity Framework’s LINQ to Entities or ObjectQueries

Julie’s Querying with LINQ to Entities vs ObjectQuery in EF post of August 5, 2008 describes the tradeoffs between LINQ to Entities and ObjectQuery queries, including QueryBuilder syntax.

Danny Simmons Updates the .NET Rocks Audience with the Latest Entity Framework v1 News

In Show #365 of August 5, 2008 Daniel Simmons on Entity Framework v1! updates his April 5, 2007 Daniel Simmons on ADO.NET Entity Framework (Show #226) interview with new details on EF v1’s release in Visual Studio 2008 SP1, Plain Old CLR Objects (POCO), and other recent EF events.

Updated List of Third-Party LINQ Providers

“LinqMaster”’s Links to LINQ Providers post of April 5, 2008 provides a comprehensive list of third-party LINQ providers. The only obvious missing provider is Agnes Molnar’s new LINQ4SP (LINQ to SharePoint) implementation.

Kristofer Andersson: Adding More Tools to the Huagati DBML Toolset for LINQ to SQL

The Huagati DBML Toolset for LINQ to SQL consists today of a Visual Studio 2008 add-in that “adds menu options for synchronizing LINQ to SQL designer diagrams with the underlying database, and for renaming entities and members to use .NET naming conventions.”

In his Tools - Part 3 - Add-ins - Writing optimized queries post of August 5, 2008, Kris describes:

Tool #3: DBML Explorer “that combines the information from the O/RM side (DBML file / LINQ to SQL designer) with schema information, table details, column details, index information, foreign keys, etc. With this information at hand directly in Visual Studio it will be easier to write LINQ queries against the database while being aware of what indexes are available for the query, comparative size of tables, etc.”

Tool #4: DBML Query Builder “extends the DBML Explorer with functionality to quickly select the relevant tables and columns, join types, groupings/aggregates, criteria, formulas and then let the tool compose the Linq query with on-screen advice on index usage etc. This tool will help beginners get up to speed with LINQ syntax as well as save typing for those who are not amused by writing queries.”

Tool #5: LINQ Query Analyzer catches bad queries “at design time in Visual Studio instead of later in SQL Server Profiler while troubleshooting performance issues in a production environment.”

Kris plans to release Tool #3 this week and will update this post when RTM dates for the other two tools are final. Existing DBML Tools license holders are eligible for upgrades of the new tools.

The August 2008 issue of ACM’s Queue Magazine Features Object/Relational Mapping Tool Articles

This month’s issue of Queue Magazine features an interview and three articles about O/RM tools:

Each of the three articles is well worth the read.

Shawn Wildermuth Finishes His Implementing IUpdatable Trio

Shawn’s Implementing IUpdatable (Part 3) post of August 3, 2008 is the final episode in his three part series about implementing IUpdatable to make NHibernate back-ends updatable when used with ADO.NET Data Services.

This post covers implementing the ClearChanges, ResolveResource(), ReplaceResource(), SetReference(), AddReferenceToCollection(), RemoveReferenceFromCollection() and SaveChanges() methods.

Paulo Morgado Demonstrates the Differences in Expression Trees Generated by VB and C#

Inspired by LLBLGen Pro’s Frans Bouma and Jon Skeet, Paulo’s C# And Visual Basic Generate Different Expression Trees post of August 4, 2008 demonstrates in considerable detail that:

    • The C# compiler will issue a virtual call to the virtual member in the class where it’s declared as virtual.
    • The Visual Basic compiler will issue a virtual call to the overriding member on the class that overrides it.

Chris Swain Provides Workarounds for Two Dynamic Data Problems

In his Distracted by Dynamic Data post of August 4, 2008, Chris describes problems with absolutely positioning dynamic controls on edit forms and proposes two solutions. He also provides a solution that enables the Dynamic Data Future’s DynamicLabel “to also set its Text property to the column DisplayName making the DynamicLabel truly dynamic.”

Pat Helland Discusses One of His Favorite Topics: Unreliability and Eventual Consistency of Transactions

Now that Pat’s a member of the SQL Server team, his Memories, Guesses, and Apologies presentation at Tech*Ed 2008 Developer has a bit less relevance because unreliability and eventual consistency of transactions is more of a problem for Cloud Computing databases that use large-scale replicated file systems, such as Google App Engine and Amazon SimpleDB, rather than today’s relational database systems. So Pat, defines “subjective consistency” in terms of memories, guesses, and apologies.

Update 8/6/208: Jeremy Stell-Smith’s Eventual Consistency, or things will all work out...eventually post of August 5, 2008 discusses issues with eventual consistency on Amazon SimpleDB.

Software as a Service Has It’s Pitfalls: Windows Live ID Fail at MSDN Downloads

This morning I tried to log into my MSDN subscriber account to download SQL Server 2008. I logged in automatically to msdn.microsoft.com, but received the page below when attempting to log into the downloads section:

I assumed MSDN Downloads hadn’t resigned its Windows Live ID membership, so I took the “try again later” advice and after 15 minutes and a few of retries, was able to log in and start the download.

Monday, August 04, 2008

Comparison of Code and T-SQL Queries for LINQ to SQL and Entity Framework Databound Forms

The Drag-and-Drop Master/Details Windows Forms Still Missing from Entity Framework SP1 Beta post of August 4, 2008 describes the need for sample code to demonstrate that drag-and-drop databinding with promised post-Visual Studio 2008 SP1 Beta improvements is as effective as that of LINQ to SQL for common usage patterns, such as fully editable master/detail/subdetail forms.

Note: This post will be updated shortly with code to change Product EntityRef[erence]s. 

LINQ to SQL Master/Detail/Subdetail Form Example

LINQ to SQL query execution for Customers/Orders/Order_Details form with the last five Orders and their Order_Details items displayed for a selected customer:

private void MainForm_Load(object sender, EventArgs e)
{
    ctxNwind = new NorthwindDataContext();
    DataLoadOptions options = new DataLoadOptions();
    // Load only the last five orders, newest first
    options.AssociateWith<Customer>(c => c.Orders.
        OrderByDescending(o => o.OrderDate).Take(5));
    options.LoadWith<Order>(o => o.Order_Details);
    ctxNwind.LoadOptions = options;
    customerBindingSource.DataSource = ctxNwind.Customers;
    employeeBindingSource.DataSource = ctxNwind.Employees;
    shipperBindingSource.DataSource = ctxNwind.Shippers;
    productBindingSource.DataSource = ctxNwind.Products;
    cboCustomer.DataSource = ctxNwind.Customers;
    cboCustomer.DisplayMember = "CustomerID";
}

The following four T-SQL batches run on startup to populate ComboBox and ComboBoxColumn lists:

SELECT [t0].[CustomerID], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactTitle], [t0].[Address], [t0].[City], [t0].[Region], [t0].[PostalCode], [t0].[Country], [t0].[Phone], [t0].[Fax]
FROM [dbo].[Customers] AS [t0]
SELECT [t0].[EmployeeID], [t0].[LastName], [t0].[FirstName], [t0].[Title], [t0].[TitleOfCourtesy], [t0].[BirthDate], [t0].[HireDate], [t0].[Address], [t0].[City], [t0].[Region], [t0].[PostalCode], [t0].[Country], [t0].[HomePhone], [t0].[Extension], [t0].[Photo], [t0].[Notes], [t0].[ReportsTo], [t0].[PhotoPath]
FROM [dbo].[Employees] AS [t0]
SELECT [t0].[ShipperID], [t0].[CompanyName], [t0].[Phone]
FROM [dbo].[Shippers] AS [t0]
SELECT [t0].[ProductID], [t0].[ProductName], [t0].[SupplierID], [t0].[CategoryID], [t0].[QuantityPerUnit], [t0].[UnitPrice], [t0].[UnitsInStock], [t0].[UnitsOnOrder], [t0].[ReorderLevel], [t0].[Discontinued]
FROM [dbo].[Products] AS [t0]
The following executes on startup and the first time the user selects a customer other than the first:
exec sp_executesql N'SELECT TOP (5) [t0].[OrderID], [t0].[CustomerID], [t0].[EmployeeID], [t0].[OrderDate], [t0].[RequiredDate], [t0].[ShippedDate], [t0].[ShipVia], [t0].[Freight], [t0].[ShipName], [t0].[ShipAddress], [t0].[ShipCity], [t0].[ShipRegion], [t0].[ShipPostalCode], [t0].[ShipCountry]
FROM [dbo].[Orders] AS [t0]
WHERE [t0].[CustomerID] = ((
    SELECT [t2].[CustomerID]
    FROM (
        SELECT TOP (1) [t1].[CustomerID]
        FROM [dbo].[Customers] AS [t1]
        WHERE [t1].[CustomerID] = @p0
        ) AS [t2]
    ))
ORDER BY [t0].[OrderDate] DESC',N'@p0 nvarchar(5)',@p0=N'ALFKI'

The following query runs up to five times (depending on the number of orders for the customer) after the preceding query:

exec sp_executesql N'SELECT [t0].[OrderID], [t0].[ProductID], [t0].[UnitPrice], [t0].[Quantity], [t0].[Discount]
FROM [dbo].[Order Details] AS [t0]
WHERE [t0].[OrderID] = @x1',N'@x1 int',@x1=11087

and @x1=11011, 10952, 10835, 10702 for ALFKI.

Another Customers query runs at this point for unknown reasons.

Note 1: Changes to Salesperson (EmployeeID) and ShipVia (ShipperID) don’t affect the Order entity until changes are saved and data is refreshed.

Note 2: You can’t edit the ProductID value of an Order_Detail entity because it’s a member of the composite primary key. You must delete and recreate the entity.

Entity Framework v1 SP1 Beta Emulated Master/Details/Subdetails Form Example

Entity Framework query execution for Customers/Orders/Order_Details form with last five orders and details displayed for selected customer.

The following code loads the data sources for the ComboBox and ComboBoxColumns and calls event handlers to fill the Orders and Order_Details DataGridViews with the first customer’s last five orders:

private void MainForm_Load(object sender, EventArgs e)
{
    ctxNwind = new NorthwindEntities();
    customerBindingSource.DataSource = ctxNwind.Customers.ToList<Customer>();
    employeeBindingSource.DataSource = ctxNwind.Employees.ToList<Employee>();
    shipperBindingSource.DataSource = ctxNwind.Shippers.ToList<Shipper>();
    productBindingSource.DataSource = ctxNwind.Products.ToList<Product>();
    isLoaded = true;
    customerBindingSource.MoveFirst();
    customerBindingSource_CurrentChanged(null, null);
    // Reset AllowNew = true to add a pending new order
    orderBindingSource.AllowNew = true;
    cboCustomer.DataSource = ctxNwind.Customers;
    cboCustomer.DisplayMember = "CustomerID";
}
The orderBindingSource.AllowNew reset is required to enable adding a new order. Without resetting the property value, you can’t add a new order from the UI or with the orderBindingSource.New() method because the ObjectBindingSources.Items collection has become fixed-size. The instruction must be at this particular location in the code to prevent loss of the ComboBoxColumn’s selection.
The following two methods synchronize Orders and Order_Details with Customer and Order selections:
// Emulate behavior of OrdersBindingSource = CustomersBindingSource
// with Orders.DataMember = "Orders"
private void customerBindingSource_CurrentChanged(object sender, EventArgs e)
{
    if (isLoaded)
    {
        // Get the current Customer instance
        Customer cust = (Customer)customerBindingSource.Current;
        // Attach the Orders and Order_Details 
        cust.Orders.Attach(cust.Orders.CreateSourceQuery().
            OrderByDescending(o => o.OrderDate).Take(5));
        foreach (Order o in cust.Orders)
            o.Order_Details.Attach(o.Order_Details.CreateSourceQuery().
                Where(d => d.OrderID == o.OrderID));

        // Get the Customer’s associated Orders
        orderBindingSource.DataSource = 
            cust.Orders.Where(o => o.Customer.CustomerID == cust.CustomerID);
        orderBindingSource.MoveFirst();
        int row = 0;
        foreach (Order ord in orderBindingSource)
        {
            // Provide foreign-key values for SalesPerson and ShipVia ComboBoxes
            orderDataGridView.Rows[row].Cells[1].Value = ord.Employee.EmployeeID;
            orderDataGridView.Rows[row].Cells[5].Value = ord.Shipper.ShipperID;
            row++;
        }
        // Bind Order_Details to the first Order
        orderBindingSource_CurrentChanged(null, null);
    }
}
// Emulate behavior of Order_Details Binding Source = OrdersBindingSource
// with Order_Details.DataMember = "Order_Details" (called by highlighted line above)
private void orderBindingSource_CurrentChanged(object sender, EventArgs e)
{
    Order order = (Order)orderBindingSource.Current;
    if (order != null)
        order_DetailBindingSource.DataSource = order.Order_Details;
}
The following four T-SQL batches run on startup to populate ComboBox and ComboBoxColumn lists (similar to LINQ to SQL batches):
SELECT 
[Extent1].[CustomerID] AS [CustomerID], [Extent1].[CompanyName] AS [CompanyName], 
[Extent1].[ContactName] AS [ContactName], [Extent1].[ContactTitle] AS [ContactTitle], 
[Extent1].[Address] AS [Address], [Extent1].[City] AS [City], 
[Extent1].[Region] AS [Region], [Extent1].[PostalCode] AS [PostalCode], 
[Extent1].[Country] AS [Country], [Extent1].[Phone] AS [Phone], [Extent1].[Fax] AS [Fax]
FROM [dbo].[Customers] AS [Extent1]
SELECT 1 AS [C1], 
[Extent1].[EmployeeID] AS [EmployeeID], [Extent1].[LastName] AS [LastName], 
[Extent1].[FirstName] AS [FirstName], [Extent1].[Title] AS [Title], 
[Extent1].[TitleOfCourtesy] AS [TitleOfCourtesy], [Extent1].[BirthDate] AS [BirthDate], 
[Extent1].[HireDate] AS [HireDate], [Extent1].[Address] AS [Address], 
[Extent1].[City] AS [City], [Extent1].[Region] AS [Region], 
[Extent1].[PostalCode] AS [PostalCode], [Extent1].[Country] AS [Country], 
[Extent1].[HomePhone] AS [HomePhone], [Extent1].[Extension] AS [Extension], 
[Extent1].[Photo] AS [Photo], [Extent1].[Notes] AS [Notes], 
[Extent1].[PhotoPath] AS [PhotoPath], [Extent1].[ReportsTo] AS [ReportsTo]
FROM [dbo].[Employees] AS [Extent1]
SELECT 
[Extent1].[ShipperID] AS [ShipperID], [Extent1].[CompanyName] AS [CompanyName], 
[Extent1].[Phone] AS [Phone]
FROM [dbo].[Shippers] AS [Extent1]
SELECT 
1 AS [C1], 
[Extent1].[ProductID] AS [ProductID], [Extent1].[ProductName] AS [ProductName], 
[Extent1].[QuantityPerUnit] AS [QuantityPerUnit], [Extent1].[UnitPrice] AS [UnitPrice], 
[Extent1].[UnitsInStock] AS [UnitsInStock], [Extent1].[UnitsOnOrder] AS [UnitsOnOrder], 
[Extent1].[ReorderLevel] AS [ReorderLevel], [Extent1].[Discontinued] AS [Discontinued], 
[Extent1].[CategoryID] AS [CategoryID], [Extent1].[SupplierID] AS [SupplierID]
FROM [dbo].[Products] AS [Extent1]

The following executes on startup and the first time the user selects a customer other than the first:

exec sp_executesql N'SELECT TOP (5) 
[Project1].[C1] AS [C1], 
[Project1].[OrderID] AS [OrderID], [Project1].[OrderDate] AS [OrderDate], 
[Project1].[RequiredDate] AS [RequiredDate], [Project1].[ShippedDate] AS [ShippedDate], 
[Project1].[Freight] AS [Freight], [Project1].[ShipName] AS [ShipName], 
[Project1].[ShipAddress] AS [ShipAddress], [Project1].[ShipCity] AS [ShipCity], 
[Project1].[ShipRegion] AS [ShipRegion], 
[Project1].[ShipPostalCode] AS [ShipPostalCode], 
[Project1].[ShipCountry] AS [ShipCountry], [Project1].[CustomerID] AS [CustomerID], 
[Project1].[EmployeeID] AS [EmployeeID], [Project1].[ShipVia] AS [ShipVia]
FROM ( SELECT 
    [Extent1].[OrderID] AS [OrderID], [Extent1].[CustomerID] AS [CustomerID], 
    [Extent1].[EmployeeID] AS [EmployeeID], [Extent1].[OrderDate] AS [OrderDate], 
    [Extent1].[RequiredDate] AS [RequiredDate], 
    [Extent1].[ShippedDate] AS [ShippedDate], [Extent1].[ShipVia] AS [ShipVia], 
    [Extent1].[Freight] AS [Freight], [Extent1].[ShipName] AS [ShipName], 
    [Extent1].[ShipAddress] AS [ShipAddress], [Extent1].[ShipCity] AS [ShipCity], 
    [Extent1].[ShipRegion] AS [ShipRegion], 
    [Extent1].[ShipPostalCode] AS [ShipPostalCode], 
    [Extent1].[ShipCountry] AS [ShipCountry], 
    1 AS [C1]
    FROM [dbo].[Orders] AS [Extent1]
    WHERE ([Extent1].[CustomerID] IS NOT NULL) AND ([Extent1].[CustomerID] = @EntityKeyValue1))  AS [Project1]
ORDER BY [Project1].[OrderDate] DESC',N'@EntityKeyValue1 nchar(5)',@EntityKeyValue1=N'ALFKI'

Like LINQ to SQL, the following query runs up to five times (depending on the number of orders for the customer) after the preceding query:

exec sp_executesql N'SELECT 
1 AS [C1], 
[Extent1].[OrderID] AS [OrderID], [Extent1].[ProductID] AS [ProductID], 
[Extent1].[UnitPrice] AS [UnitPrice], [Extent1].[Quantity] AS [Quantity], 
[Extent1].[Discount] AS [Discount]
FROM [dbo].[Order Details] AS [Extent1]
WHERE ([Extent1].[OrderID] = @EntityKeyValue1) AND ([Extent1].[OrderID] = @p__linq__1)',N'@EntityKeyValue1 int,@p__linq__1 int',@EntityKeyValue1=11087,@p__linq__1=11087

and @p__linq__1=11011, 10952, 10835, 10702 for ALFKI.

Note 1: Deleting and recreating Order entities to accommodate changes to Salesperson (EmployeeID) and ShipVia (ShipperID) aren’t acceptable because OrderID is an int identity field.