Wednesday, July 02, 2008

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

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

Tim Mallalieu Proposes “The Great Entity Smackdown” with a Fictitious Development Project

Having endured the “ADO.NET Data Services No-Confidence Vote” agonies, created an Entities Wiki (see the end of this post) for folks to publish their favorite patterns and scenarios, and witnessed the argument in the comments section of the Wiki’s front page, Tim proposes in his The Great Entity Smack down post of July 1, 2002 to:

[C]reate "The Great Entity Smack Down". My thought is that we could go get a bunch of folks that represent different perspectives in the community in a public forum. We put together a fictitious development project (oh let's say pet shop for grins) and we get representatives of different camps to discuss/debate how they would approach the project.

I’ve offered my OakLeaf University sample database as an alternative to Northwind or AdventureWorks. It’s the standard Department/FacultyOrStaff/Student/Title/Course/ Grade/etc. with 2,311 Employee and 30,000 or so Student entries.

The database provides the data source for my turn-of-the-century VB6 GroupPol.exe program that generates thousands of ActiveDirectory security principals with very detailed properties:

GroupPol uses ADSI 2.5 to generate OUs and Security Groups and them populates them with Students, Faculty, and Non-Faculty Staff. The original version created Windows NT accounts with Exchange Mailboxes for upgrading to Windows 2000 domains. This introduces the opportunity to add some LDAP spice to the project.

Dinesh Kulkarni Describes LINK to SQL’s Internal Data Caching

Dinesh’s LINQ to SQL Tips 9: Understanding DataContext's internal caching post of July 1, 2008 observes that LINQ to SQL “is not intended to be a mid-tier caching component. It is not a cache and it does not pretend to be one.”

He then goes on to explain how LINQ to SQL’s DataContext manages object identity, change tracking, and object persistence.

Added: 7/2/2008

Eugenio Pace Offers Download of His Simple GeoRSS Library for Windows Live Maps

His Simple GeoRSS utility library – released post of July 1, 2008 includes the source code for a library that works with Windows Live Maps and supports points, lines, polygons, links, and icons. The library also has a GeoRSSBuilder that converts the model into a syndication feed.

Eugenio created the library for use with his integration of Live Maps with the LitareHR SSDS sample applications, as described in his LitwareHR and GeoRSS post of June 27, 2008 and noted in the “Eugenio Pace Adds a Virtual Earth GeoRSS Property to His LitwareHR SSDS Project” topic of LINQ and Entity Framework Posts for 6/25/2008+.

Added: 7/2/2008

Craig Shoemaker Creates an ASP.NET Dynamic Data Site with LINQ to SQL in Its Own Data Layer

In 6 Steps to N-Tier ASP.NET Dynamic Data of July 1, 2008 Craig asserts:

Moving the data context from the web layer to a lower level will allow you to reuse the LINQ to SQL data context as well as any other logic or wrappers you create around the data model.

In his example, the lower level is a class library for the DataContext. He admits at the conclusion of his post:

Obviously the application created in this post is not a true n-tier application, but this shows you what you need to know for you to architect your applications as appropriate.

Added: 7/2/2008

Mike Taulty Uncovers a Glitch in Using Timestamps for Managing LINQ to SQL Concurrency Conflicts

Mike’ On LINQ to SQL, Concurrency and Timestamps post of July 1, 2008 observes that if your SaveChanges() invocation retrieves three entities with timestamps, you modify the timestamp value of two entities on the client, and then save changes, a exception occurs, and the transaction rolls back, but it doesn’t fix the changed timestamp value from the update on the server.

He explains that the exception occurs because of the AutoUpdate property setting and describes a workaround to solve the problem.

I commonly use timestamps for concurrency conflict management because they simplify the process and are compatible with the Microsoft Sync Framework. However, I haven’t encountered this problem (yet.)

Added: 7/1/2008 16:00 PDT

Marcel Lopez Ruiz Warns that ADO.NET Data Services Beta Chokes on Complex (Value) Types

Marcelo posted ADO.NET Data Services Beta bits don't support complex types on July 1, 2008 to warn users that only scalar property values can be used for service operations.

Complex types, such as Address, are better known as value types because they are useful only for their value, don’t exist outside the context of the entity that contains them, and don’t have keys to identity themselves.

This omission eliminates one more excuse for favoring Entity Framework over LINQ to SQL (or any other IQueryable() implementation) as an Astoria source.

He didn’t say whether support for complex types is planned for Astoria v1. I’ve asked that question in a comment.

Added: 7/1/2008 16:15 PDT

Sasha Goldshtein Believes LINQ to SQL is Under-appreciated

In his LINQ To SQL: More Useful Than You'd Think post of July 1, 2008, Sasha concludes that the three reasons for substituting Entity Framework (EF) for LINQ to SQL are:

    • The ability to query relational stores other than Microsoft SQL Server
    • A full textual query language not limited to LINQ's language support
    • Advanced mapping facilities, such as mapping a single class to multiple tables

However, I would add fourth and reasons:

  • Microsoft’s SQL Server Data Programmability (DP) group is fully committed to Entity Framework as its data platform going forward
  • The DP group is in the process of deprecating LINQ to SQL by not-so-benign neglect.

Sasha describes his occupation and use of O/RM tools:

I'm a Senior Consultant and Instructor for Sela Group.  I consult and teach in many areas including Windows internals, CLR internals, .NET and native performance issues and troubleshooting, production debugging, Vista ... (so basically everything goes). … [Link added.]

I am not an ORM expert: I've used NHibernate in the past, I've played around with the Entity Framework and I'm using LINQ to SQL in my projects.

Sasha Continues with A Unique Programming Style for n-Tier Apps with LINQ to SQL

His LINQ To SQL: Surprising Features post of later the same day demonstrates how to generate an XML mapping file with SqlMetal.exe, substitute hand-written WCF data contracts for the autogenerated classes. Sasha describes his transformation of the ordinary drag-and-drop, demo-style approach as:

We have taken a single representation of the data, which was well-suited for transferring it over WCF, and adapted it so that it can be used directly with our LINQ to SQL data accessor.  We added information required for database normalization, but we didn't repeat ourselves: Not even one of the data properties appears in the program more than once.  This non-intrusive capability of benefiting from LINQ to SQL is a key metric of its success.

Sample code is available for down load from a link on Sasha’s site.

Added: 7/1/2008 15:45 PDT

New SQLite Release Gains LINQ Implementation and Supports Entity Framework

Hwaci’s System.Data.SQLite site announced the availability of version 1.0.51.0 Jul 1, 2008
for ADO.NET 2.0, which includes VS 2005/VS 2008 design time. According to the features list:

You can add a SQLite connection to the Server Explorer, create queries with the query designer, drag-and-drop tables onto a Typed DataSet and more! SQLite's designer works on all editions of Visual Studio 2005/2008, including all Express Editions.

SQLite’s EF implementation is beta-quality in this release.

Ian Cooper Winds Up His “Architecting LINQ to SQL” Series with Part 10, “End of the Line”

Ian’s final episode covers the new features he’d like to see in LINQ to SQL:

  • Support for Value Types.
  • Support for changing loading options.
  • Support for ordered relationship types.
  • Support for table per sub-class mapping.

He’s less optimistic about prospects for the following features:

  • Expose the provider model.
  • Include an explicit in-memory provider.
  • Support for second-level caching.

According to Matt Warren, the provider model is present, but turned off. I’m not optimistic about the probability for any new LINQ to SQL features. LINQ to SQL was a product of the C# team and the SQL Server Data Programmability group, who are bringing us Entity Framework v1, now owns LINQ to SQL. I believe LINQ to SQL already is in deprecated product purgatory (see my Is the ADO.NET Team Abandoning LINQ to SQL? post of May 23, 2008.)

Ian acknowledged my request for a sample messaging implementation:

Hopefully, part 10 will continue with a sample implementation of messaging to update entities of a less trivial service.

With this response:

Roger Jennings requested that I give more than a trivial example of how to do messaging for n-tier scenarios. I'm flattered by Roger's confidence, though I feel that Greg or Udi would be better placed to do a introductory piece on messaging. But if there is demand I will give it a try.

Please indicate your demand by comments on Ian’s and this post.

Shawn Wildermuth Begins Implementing an NHibernate Data Provider for ADO.NET Data Services

Shawn’s Implementing IUpdatable (Part 1) post of July 1, 2008 describes the SQL Server Data Programmability groups shenanigans to prevent use of LINQ to SQL as a updatable data provider for Astoria by implementing the IUpdatable interface in Astoria and restricting its use for Entity Framework data sources only. (Note that this jewel isn’t disclosed in Pablo Castro’s “transparent development” blog posts, as far as I can determine.)

NHibernate’s LINQ implementation exposes a read-only DataContext to Astoria that requires a workaround for an Astoria bug (keys in a base class must have names with an “ID” suffix) to operate correctly. Shawn says:

For the first pass, I am going to implement IUpdatable directly on NHibernateContext and refactor it later for less tight coupling. While I am at it, I also want to add support for IExpandProvider so that we can do expansions through NHibernate.

He concludes, “I'll keep you posted with my experience dealing with [the rest of the interface.]”

Steve Naughton Takes a Second Run at Explaining ASP.NET Dynamic Data’s Routing Features

ASP.NET Dynamic Data uses the new Routing classes introduced in .NET 3.5 SP1 to support ASP.NET MVC. Steve’s Dynamic Data and Routes (Take 2) of July 1, 2008 starts with “this thread Manual Scaffolding and Routing on the DynamicData forum ASP.NET Dynamic Data” and provides detailed code examples for basic routes and routes with parameters.

If you’re new to routing and intend to hone ASP.NET MVC skills, here’s the place to start learning routing techniques. (Dynamic Data provides a very quick way to scaffold a routing test bed.)

Mike Taulty Provides Guided Tour of Databinding a Silverlight DataGrid Control to an ADO.NET Data Services Layer

Mike’s Silverlight and ADO.NET Data Services post of June 30, 2008 is a fully illustrated tutorial that explains in detail how to create an Astoria WCF service, add a Entity Data Model back end, create a Silverlight client, and then add and bind a DataGrid to the service proxy.

Silverlight and ADO.NET Data Services ( 2 ) of July 1, 2008 covers updating, deleting, and inserting rows in the DataGrid. Mikes closing paragraph:

From there I think the next steps would be to think about inserting related entities ( 1 to many and many-to-many ), checking status codes, handling errors and so on.

Implies that there might be posts in store on these topics.

Bart DeSmet Provides a Step-by-Step, Illustrated Tutorial for Creating a Velocity Cache on a One-Host Cluster

If you’re using Entity Framework or LINQ to SQL with ASP.NET Web projects, you might need to cache a substantial number of objects in session state for multiple sessions of data-intensive Web apps spread across multiple Web servers. In this case, Velocity should be able to increase scalability substantially by distributing the cached objects across the cluster. 

A Lap Around Microsoft "Velocity" - Cache It NOW! of June 30, 2008 is provides Introduction and Configuration sections following by instructions on how to use Velocity, accompanied by detailed screen captures. Bart uses the “degenerate form of a cluster” (a one-host cluster) for demonstration purposes.

Troy Magennis Provides Links to Tech*Ed Resources for Velocity

Troy’s Project “Velocity” A Distributed In-Memory Application Cache post of June 30, 2008 provides links to Anil Nori and Muralidhar Krishnaprasad’s Velocity slides from Tech*Ed Developers 2008, the Velocity blog, and other resources.

Om Malik Posts Video Interview with Microsoft’s “Internet Information Czar,” Debra Chrapaty

Microsoft is expanding its world-wide collection of data centers at a feverish pace, a fact that should please prospective users of SQL Server Data Services. Microsoft’s corporate VP of global foundation services, Debra Chrapaty, is in change of the data center expansion project.

Om’s Inside Microsoft’s Internet Infrastructure & Its Plans For The Future post of June 30, 2008 links to a video interview with Chrapaty conducted at his Structure 08 conference in San Francisco.

Tim Mallalieu Analyzes What the Term Lazy Loading Implies

Tim got some help from Martin Fowler about what the term “lazy loading” means to most developers: “Martin indicated that the notion of lazy load expects that one does not have to do anything beyond dereference operations to retrieve the related instances.”

Tim’s To Lazy Load or not to Lazy load? post of June 24, 2008 (which I missed by accident) asserts that Martin’s definition should (by default) be able to address a many:one member as Order.Customer.City and receive the scalar City value, not a “not found” exception.

Fowler also recommended that the term for the present model, “explicit lazy loading,” is “an overload of a clear term.” So the team will use “explicit loading” from now on.

Added: 7/1/2008 15:45 PDT

Entity Framework Design Group Opens New Entities Wiki

Tim Mallalieu says on the Front Page, “This is a Wiki site set up by some folks on the ADO.NET Entity Framework Team to get additional information on patterns and scenarios that people are currently using with general ORM stacks.” It appears to have opened for business with little fanfare on June 26, 2008.

You can read the pages (but not add comments, add or edit pages, or view user details) without logging in, which requires requesting permission. There are relatively few users so far, but some topics are quite active with large number of pages and comments from “heavy hitters” of the recent “No-Confidence” dustup (e.g., Scott Bellware, Ayende Rahien, Kathleen Dollard, and Ward Bell.)

3 comments:

Anonymous said...

Regarding this:

Note that this jewel isn’t disclosed in Pablo Castro’s “transparent development” blog posts, as far as I can determine

I hinted at it here when we were still exploring:
http://blogs.msdn.com/astoriateam/archive/2007/09/27/astoria-data-sources-and-system-layering.aspx

And then Pratik started to describe it here:
http://blogs.msdn.com/astoriateam/archive/2008/04/10/iupdatable-ado-net-data-services-framework.aspx

I'm sure there are some topics we missed in the public design notes...just not this one :)

Anonymous said...

Hi Roger,

I think it is really important that the people that like LINQ to SQL are vocal about it and put pressure on the team to take it forward as a serious tool.

In a discussion on the comments on my blog I mention that one option is to separate the two tools pitching LINQ to SQL as their OO ORM and EF as their data-first platform.

Sadly I think one negative aspect of the EF criticism is that it will push resources onto adding features to EF instead of in to taking LINQ to SQL forward.

So that is my rallying cry to people. Talk about what LINQ to SQL is doing for you, so that the team know it has vocal support.

Anonymous said...

Heh about that Wiki: reading some of the discussions there... I can't help but wonder how this will eventually end up in something truly valuable. Most of these discussions are about topics which are perhaps relevant for the poster, but hardly relevant for the majority out there. What's often forgotten by users of a toolkit is that the toolkit can't be morphed for 100% to fit the project of the user. I.o.w.: there's always some form of adoption to be made by the user, that's unavoidable (even when the user writes the toolkit by hand!).

I mean... "Getters and setters on a domain object are an antipattern, it breaks encapsulation". I then can only laugh out loud simply because every context/session using o/r mapper (nhibernate, linq to sql, EF...) uses change tracking mechanisms OUTSIDE the entity/domain object. They most of the time are able to persist private member variables... how is that NOT breaking encapsulation? Sure, it's 'necessary' to get things done, but that's IMHO not an excuse to allow it in one area (O/R mapper framework) but disallow it in another (your code). :)