Monday, June 16, 2008

LINQ and Entity Framework Posts for 6/12/2008+

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

Updated 6/15/2006 and 6/16/2006.

Illustrated Walkthroughs for Creating Web Apps and Web Sites with ASP.NET Dynamic Data

ASP.NET Dynamic Data projects come in two flavors:

  1. Dynamic Web applications or file-based Web sites that use either the Entity Data Model or LINQ to SQL as their data model.
  2. Static (Custom) Web sites that you create with the Dynamic Data Wizard. These sites currently are limited to LINQ to SQL only as their data source.

My forthcoming “Scaffold Web Apps with ASP.NET Dynamic Data” article for Visual Studio Magazine includes walkthroughs for creating the preceding two project types with Northwind as the backing database.

Publishing limitations precluded step-by-step screen captures, so I created two posts to illustrate the process:

  1. Dynamic Web application: ASP.NET Dynamic Data: Generate a Dynamic Administrative Web App from an Entity Data Model in Less than Five Minutes
  2. Static Wizard-generated Web site: ASP.NET Dynamic Data: Scaffold a Custom Administrative Web Site with a LINQ to SQL Data Model in Less than Five Minutes

An obvious drawback to the Wizard-generated site is lack of DynamicFilter dropdowns for filtering on EntityReference (foreign key) values.

Added: 6/15/2008

David Ebbo Explains ASP.NET Dynamic Data’s Handling of Foreign Keys in Scaffolded Dynamic Controls

David discusses how ASP.NET Dynamic Data displays EntityReferences from foreign keys in his Understanding foreign keys and relationship columns in Dynamic Data post of June 13, 2008. The discussion applies to grids and details views with Entity Data Model and LINQ to SQL as data models.

As David mentions, foreign key values (usually integers) appear when you use LINQ to SQL as the data model. The Entity Data Model replaces foreign key with Navigation Properties (EntityRefs.)

One reason folks become confused about foreign-key handling is that Dynamic Data requires LINQ-enabled data sources, such as the LinqDataSource and EntityDataSource, which implies using object terminology (e.g., classes, types, associations, entities, entity sets, entity references, etc.). This usage conflicts with relational terminology (primary and foreign keys.) The help files and blog posts have a tendency to favor the relational (data) dialect.

Mike Taulty Tackles Implementing IUpdatable() for LINQ to SQL DataContexts Backing ADO.NET Data Services

Mike’s ADO.NET Data Services - IUpdatable on LINQ to SQL post of June 14, 2008 discusses four possibilities for creating an updatable LINQ to SQL data model for use with ADO.NET Data Services. His final choice (#4) requires the developer to derive from <T> manually, as is the case with ADO.NET Data Service’s Web services.

Note: The Data Programmability group’s failure to update LINQ to SQL with an IUpdatable implementation is one more nail in the product’s coffin. (I neglected to mention this issue in my Is the ADO.NET Team Abandoning LINQ to SQL? post of May 23, 2008.

asp.netPRO Magazine’s June Issue Carries an ASP.NET Dynamic Data Article That’s Ina Finally Accessible Online

The aspnetNOW nesletter for June 12, 2008 says the “ASP.NET team's own Marcin Dobosz and Scott Hunter provide an introduction to Dynamic Data,” and “the June issue of asp.netPRO is now available as a FREE PDF.“

The problem is that it isn’t available. The asp.netPRO folks forgot to renew their NetworkSolutions domain registration, which expired on June 8, 2008.

When (and if) they get their domain registration problems straightened out, I’ll add a new blurb.

“An Introduction to ASP.NET Dynamic Data: Rapidly Create Rich Data-Bound Sites” is now accessible at

Bart De Smet Posts First Episode of His LINQ to MSI Implementation

Bart says in his LINQ to MSI - Part 1 – Interop post of June 13, 2008:

So, in this post of this series we'll take a look at some very simple MSI interop, giving us a basic data provider for MSI databases, mirrored after the typical structure of .NET data providers like System.Data.SqlClient.

And then goes on to discuss:

  • Interop signatures
  • Respecting well-known patterns
    • The connection
    • The command
    • The data reader
  • Sample

He adds a postscript to the preceding post in LINQ to MSI - Part 1 bis - Interop with SafeHandles of June 14, 2008.

Mike Taulty Diagnoses DataSvcUtil’s Namespace Errors When Creating Web Service Proxies

Mike solve issues with “The 'Namespace' attribute is invalid - The value ''  is invalid according to its datatype '’” errors in his ADO.NET Data Services and LINQ to SQL - Errors Generating Proxy Code with DataSvcUtil.exe post of April 13, 2008.

Matthieu Mezil Illustrates Use of AsEnumerable() That Mystifies Me

Matthieu’s AsEnumerable: not only to use unsupported methods post of June 13, 2008 discusses the differences in the results of a pair of complex LINQ to SQL queries whose primary distinction is use of AsEnumerable() to solve a problem obtaining Northwind Order instances with OrderDates in 1998 having French customers together with their Customer instances.

So I wrote the following relatively simple query that returned what I thought Matthieu was after:

from o in Orders
where o.OrderDate.Value.Year >= 1998 && o.Customer.Country == "France"
select new {Order = o, Customer = o.Customer};

The result of the above query in LINQPad and SQL Server Management Studio appear in my Matthieu Mezil Illustrates Use of AsEnumerable() That Mystifies Me post of June 14, 2008. The post also includes results of running Matthieu’s T-SQL batches which 1) return all 270 orders for 1998 or 2) are a LEFT OUTER JOIN of all 1998 orders with 23 French Customer records.

I’m sure I must be missing a point, but I don’t know what it is.

Update 6/15/2008 1600 PST: Adding AsEnumerable() causes immediate execution of the inner query which returns and OUTER JOIN resultset of 270 rows. Local (client-side) filtering reduces the number of rows to 23. Use of AsEnumerable() in this case unleashes bad mojo. See Matthieu’s comment and the second Update.

Eugenio Pace Posts a New SQL Server Data Services Sample: A Provider for BlogEngine.NET

Eugenio’s Another SSDS sample: BlogEngine.NET on SSDS post of June 11, 2008 describes his SQL Server Data Services (SSDS) provider’s source code for the BlogEngine.NET 1.3.1 ASP.NET blog project as follows:

  1. The SSDS based BlogProvider
  2. An SSDS based Membership & Role Providers for the web site
  3. Unit tests for all (with about 93% coverage for the provider)
  4. A simple tool for pre-loading the SSDS container with information that BlogEngine needs to start

He also says “The new SSDS BlogProvider also uses patterns & practices Unity application block to wire up dependencies.”

It’s related to the SSDS demo in Bill Gates’ Tech*Ed keynote and definitely worth a trial run.

Repeated from LINQ and Entity Framework Posts for 6/9/2008+ due to its importance.