Thursday, November 01, 2007

Multi-Tier Improvements Coming to Entity Framework

Julie Lerman reports in her A hint of what to look for in Entity Framework Beta3 post of November 1, 2007 that the ADO.NET team is avoiding LINQ to SQL's no "out-of-the-box multi-tier story" problem for v.1 by making the EntityKey for 1:m associations (EntityRefs) serializable for WCF messaging. 

Julie quotes a "public statement" from a program manager on the ADO.NET team, Brian Dawson, a part of which says:

What we did do was add the EntityKey as a serializational property on the relationship reference. This way, if you serialize Product, you'll get the EntityKey for Category. You can treat the CategoryReference.EntityKey  similar to a foreign key.

Brian doesn't mention n:1 associations (EntitySets), so I assume that the DataContractSerializer includes EntitySet payload(s) when serializing Entity Data Model (EDM) entities as it does for LINQ to SQL entities. In this case, making the EntityKey serializable prevents the circular reference (cycle) that the unmodified DataContractSerializer complains about if you attempt to serialize an entity with EntitySet(s) and EntityRef(s). My LINQ to SQL and Entity Framework XML Serialization Issues with WCF - Part 1 post of October 9, 2007 discusses the circular reference issue.

I've been waiting for Beta 3 to test Entity Framework and EDM because I'm hoping that it will "[d]efine the support for n-tier architectures and provide non-trivial, loosely-coupled sample projects with WCF," which is point the ninth request outlined in my Defining the Direction of LINQ to Entities/EDM post of May 29, 2007. Mike Pizzo responded in the comments: "I would love to see us do some more in-depth sample projects with WCF."

I hope my assumption regarding serialization of EntitySet(s) and EntityKey(s) is correct.