Monday, January 26, 2009

LINQ and Entity Framework Posts for 1/19/2009+

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

• Update 1/23/2009: Minor additions
• Update 1/26/2009 10:00 AM PST: Minor additions

Entity Framework and Entity Data Model (EF/EDM)

•• Greg Duncan’s LINQPad and the Entity Framework post of 1/25/2009 cites Simon Segal’s LinqPad for the Entity Framework, Shawn Wildermuth’s Using LinqPad and Entity Framework Models and Stefan Cruysberghs’ .NET - ADO.NET Entity Framework & LINQ to Entities – Part 2LINQPad post as evidence that using LINQPad with Entity Framework is “officially cool.”

•• Udi Dahan discusses issues with value objects, many:many associations and aggregated roots in his DDD & Many to Many Object Relational Mapping post of 1/24/2009.

Sanjay Nagamangalam’s detailed Customizing Entity Classes in VS 2010 post of 1/23/2009 describes expected improvement to code generation in EF v2 and VS 2010.

• Julie Lerman reports that my new “LINQ and the Entity Framework” book from WROX/Wiley has reached in her Roger Jennings' ADO.NET 3.5 is now "In Stock" on Amazon! post of 1/23/2009. My post about the arrival is here.

• Julie Lerman’s EntityObject Class Constructors post of 1/22/2009 observes that the entity classes generated by the EDM Designer don’t have a default constructor. This lets you add your own constructor to set default values for foreign keys, which is supported in by the Designer.

Julie Lerman will present two sessions about Entity Framework at Philly.NET Wednesday night (Jan 21) - Thanks INETA.

David Klein’s Why the Oakton Microsoft Application Framework (OMAF) Will Not Be Moving to The Entity Framework (EF) 1.0 or any 3rd Party ORM Products Right Now post of 1/20/2009 explains why OMAF will stick with LINQ to SQL until the ADO.NET team releases EF v2.

Many comments to the ADO.NET Team’s Migrating from LINQ to SQL to the Entity Framework: Stored Procedures for data retrieval post of 12/4/2008 reflect sentiments similar to David’s.

Kristofer Andersson describes in his Tools - Part 9 - Add-ins - Filtering intellisense dropdowns on required vs optional members post of 1/21/2009 how he used Alex James’ “simple and elegant way to filter Visual Studio’s Intellisense dropdowns by using interfaces and properties returning those interfaces” in the latest version of his Huagati DBML/EDMX Tools.

A beta version of Huagati DBML/EDMX Tools version 1.60 including this new feature is available for download here. Kris writes:

Unlike the other features in the add-in, this feature don’t require any license/activation. You can use it with or without having a license for the other add-in features.

Ken Cox’s Learning CRUD and Data Forms in Silverlight 2, Creating a Silverlight 2 Data Form - Episode 1 and Creating a Silverlight 2 Data Form - Episode 2 posts of 1/19/2009 show:

[A] small, but realistic example of how to create a CRUD (Create, Read, Update, Delete) application against the familiar Northwind database. It uses the latest stuff from Microsoft including Windows Communication Foundation, ADO.NET Data Services (Astoria), and the Entity Framework.

Ken uses VB because, in his words:

“I’m more comfortable in VB (although I write lots of C#); there’s a dearth of sample Silverlight code in VB; and people who write only in C# don’t need beginner-level content because they already know everything. <grin>”

Alex James continues his posts about Composable Services for EF v2 with The problem with Function Signatures of 1/17/2009, which introduces the issue of different representations of the same object, as analyzed by Stefan Tilkov in his link and self post of 1/16/2009 about the Atom Syndication Format’s use of the “self” relation. Stefan cites the ambiguity of using “self”:

[T]o refer to a canonical resource, i.e. the one that represents the object or entity itself in the default way. …

This has the downside that retrieving the resource identified by the outermost self link would yield something different than what you’re looking at. Whether this is acceptable or not depends on whether you consider these two resources to be “identical”. I’m undecided whether the official definition of the self link relation allows for this usage.

But in conclusion, I stand by my opinion that URIs can and should be used for identity – whatever “identity” might mean for you.

Alex concludes:

This is why things like hyperdata / and lazy-loading is so important.

A signature alone is not enough to help me call functions.

Particularly when the target function is called from somewhere with different context, data availability, and trustworthiness.

Hmm… lots of questions

PS: starting to solve this problem seems like a pre-requiste of truly Composable Services.

It seems to me to be an issue for ADO.NET Data Services also.


Matt Warren’s Building a LINQ IQueryable Provider - Part XIII is the latest (13th) episode in his IQueryable series, which covers:

    • Updates - Insert, Update & Delete operations.
    • Batch processing - true SQL Server batch processing.
    • Server language type systems - correct parameter types.
    • Mapping Changes - use the same class with multiple tables, etc.

Be prepared: The post is several feet long and contains a substantial amount of source code. Complete source code for Matt’s project to date is available at

• Damien Guard writes Multiple outputs from T4 made easy on 1/22/2009 to explain how his updated T4 templates can split the output into a single entity class per file.

Jim Wooley’s LINQ supported data types and functions post of 1/21/2009 relates:

I happened upon a listing on MSDN showing the functions and methods which are and are not supported. The full list of LINQ to SQL supported and unsupported members is available online at

As an example the following methods are shown as having translations for DateTime values: Add, Equals, CompareTo, Date, Day, Month, Year. In contrast methods like ToShortDateString, IsLeapYear, ToUniversalTime are not supported.

David Klein’s Why the Oakton Microsoft Application Framework (OMAF) Will Not Be Moving to The Entity Framework (EF) 1.0 or any 3rd Party ORM Products Right Now post of 1/20/2009 explains why OMAF will stick with LINQ to SQL until the ADO.NET team releases EF v2. (Copied from the “Entity Framework and Entity Data Model (EF/EDM)” section.)

Damien Guard announces that his LINQ to SQL templates [are] updated, now on CodePlex on 1/19/2009. The latest updates include:

  • Now licensed under the Microsoft Public License and hosted at CodePlex
  • User options specified with a var options block at the start of the template
  • Option for each class to be a separate file that is reflected in the VS project (EntityPerFile=true)
  • Detection and support of IsComposable functions
  • General code clean-up and better error handling such as missing DBML file

You can download a 05:00 screencast that shows how to use the templates here.

See Kristofer Andersson’s Tools - Part 9 - Add-ins - Filtering intellisense dropdowns on required vs optional members post that’s described in the “Entity Framework and Entity Data Model (EF/EDM)” section.

John Opincar recommends in his Expressions versus Delegates in LINQ to SQL Performance post of 1/18/2009:

Favor Expressions over Delegates when using LINQ. If you have to have a Delegate, you can always use Compile to turn your Expression into a Delegate as needed. But you can’t turn a Delegate into an Expression (that I’m aware of).

LINQ to Objects, LINQ to XML, et al.

•• Daniel Moth’s PLINQ post of 1/25/2009 demonstrates code to use “PLINQ as a black box” and create a simple demo example.

•• Jon Skeet starts a project to add LINQ operators that he believes are missing in LINQ to Objects with his Designing LINQ operators post of 1/23/2009.

Barry Dahlberg’s LINQ to NHibernate, IEnumerable vs IQueryable post of 1/21/2009 and Virtual Methods vs Extension Methods post of 1/23/2009 discuss his initial tests of the LINQ to NHibernate alpha in conjunction with Ayende’s new NHibernate Profiler.

Alex JamesLINQ to Objects and Buffer<T> post of 1/20/2009 analyzes the OrderBy() extension method’s implementation of Buffer<T>, and concludes:

[I]f the Buffer<T> class encounters an ICollection<T> it has a little optimization, that uses Count and CopyTo(..)to initialize an array with the correct size and take a copy of the data, rather enumerating and re-sizing a target array as needed.

When I thought about this I realized that my little Lazy Loading Collection class would return a Count of 0 until it is enumerated. And because the count was 0, the collection would never actually get enumerated.

So when I used OrderBy() over my collection, I get no results.

His solution to the dilemma is to “trigger… a LazyLoad whenever Count is called”.

Keith Brown creates an aggregating LINQ operator for TimeSpan types in his Linq and TimeSpan post of 1/19/2009.

ADO.NET Data Services (Astoria)

•• Udi Dahan’s Building Super-Scalable Web Systems with REST post of 12/29/2008 suggests “leveraging the Internet” with RESTful caching for a highly scalable custom weather reporting mashup. The techniques Udi describes apply to Astoria’s resource mapping to URIs.

Beth Massi adds an Office-related member to her ADO.NET Data Services series with the ADO.NET Data Services - Building an Excel Client post of 1/21/2009.

Beth Massi continues her ADO.NET Data Services series with ADO.NET Data Services - Intercepting Queries and Adding Validation of 1/21/2009.

Jon Udell’s Unifying HTTP success and failure in .NET discusses the differences in how Python’s httplib and .NET’s HttpWebRequest/HttpWebResponse pair handle some HTTP headers and respond to HTTP status codes.

Beth Massi’s ADO.NET Data Services - Enforcing FK Associations and a Fix for Deleting Entities post of 1/20/2009 describes a problem with disallowing nulls in foreign key fields for associated entities and saving changes to the parent entity and its solution. Beth also observes:

You may have issues deleting entities that are involved in an association (regardless of whether they are enforced or not). This was a bug in ADO.NET Data Services described in KB958484 and is fixed with this update. (This should be flowing along with your regularly scheduled Windows Updates but you may not have gotten it yet so if you're experiencing this issue make sure you install this fix.)  In our example I was forced to detach the category object from the client context before submitting the deletes.

ASP.NET Dynamic Data (DD)

Steve Naughton’s Setting the Initial Sort Order – Dynamic Data post of 1/23/2009 supplements the post below.

Steve Naughton makes up for an earlier posting hiatus with his Getting Default Values from List page Filters for Insert – Dynamic Data tutorial of 1/23/2009.

Steve Naughton’s Writing Attributes and Extension Methods for Dynamic Data of 1/20/2009 is “a short article on some useful tips I’ve found for writing Attributes for Dynamic Data.”

Scott Hanselman warns that the ASP.NET team’s “ASP.NET Dynamic Data 4.0 Preview 2 that was quietly put up just a month ago with this scary disclaimer:

NOTE: These previews contains features that may not be in the next version of the framework. These previews are not production quality and should be used at your own risk.

but then goes on to analyze Preview 2 in his lengthy ASP Dynamic Data Preview - More ways to exploit ADO.NET Data Services for fun and profit post of 1/19/2008.

Steve Naughton’s Dynamic Data – Cascading FieldTemplates post of 1/19/2009 discusses how to handle pairs of dropdown lists in which one list filters the source of the other list. For example, a selection in a Category dropdown changes the list of a paired (dependent)Products dropdown.

The solution is more complex that you’d think.

SQL Data Services (SDS) and Cloud Computing

This topic moved on 1/3/2009 to Azure and Cloud Computing Posts for 1/5/2009+.

SQL Server Compact (SSCE) 3.5 and Sync Services

This topic was dropped as of 1/3/2009.

Miscellaneous (WPF, WCF, MVC, Silverlight, etc.)

No significant posts in the Miscellaneous category were found as of 1/21/2009 11:30 AM PST.