Showing posts with label Serialization. Show all posts
Showing posts with label Serialization. Show all posts

Wednesday, May 21, 2008

LINQ and Entity Framework Posts for 5/19/2008+

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

Has LINQ to SQL Reached Legacy Status Less than Three Months after Launch?

LINQ to SQL was the only new data-access implementation to be included in Visual Studio 2008 when it "launched" with SQL Server 2008 and Windows Server 2008 in a series of "Heroes Happen Here" extravaganzas that started on February 27, 2008.

Judging from my Is the ADO.NET Team Abandoning LINQ to SQL? post of May 21, 2008, Microsoft appears to have ceased further development of LINQ to SQL, based on the lack of new and promised features in the LINQ to SQL SP1 Beta.

Added: May 21, 2008

Francois Vanderseypen Offers a Well-Documented Demo of a Web Client Software Factory Project that uses WCF, WF and LINQ to SQL

His Frameworks and directions (Kyiv presentation, May 2008) post of May 19, 2008 includes a link to download a large-scale Northwind Factory v.2.1 sample project that combines the Web Client Software Factory (WCSF) from CodePlex with LINQ to SQL, Windows Communication Foundation, and Workflow Foundation. The project, which builds a complete multi-tiered, Model-View-Controller (MVC) pattered Web site, includes a 26-page illustrated NorthwindFactory.docx documentation file. NorthwindFactory.docx is the last file in the .zip archive.

Francois's later Linq to SQL and Workflows post of May 21, 2008, casts doubt on the compatibility of LINQ to SQL data layers with the Workflow Foundation and raises other commonly blogged LINQ to SQL issues. He concludes:

All this leads somehow to the conclusion that [LINQ to SQL] was really not designed well to fit with the rest of the .Net 3.5 framework. Great idea, but not too well implemented. Let’s hope the final release of the Entity Framework (around [A]ugust with .Net 3.5 SP1) will bring some cures.

Francois works for Materialise Dental NV in Leuven, Belgum, the developer of "a range of products and services to aid dental specialists in the treatment of their patients," including "the SimPlant range of solutions for Computer Guided Implantology."

Added: May 21, 2008

Randolph Cabral Adds Business Entity Classes to His N-Tier LINQ to SQL Project

In Exploring N-Tier Architecture with LINQ to SQL (Part 4 of n) of May 21, 2008, Randolph "attempt[s] to build out the domain model and use it in our web UI layer to demonstrate how we could interact with the business entities."

Added: May 21, 2008

Ben Hall Recommends When and How to Use Stored Procedures vs. User-Defined Functions with LINQ to SQL

Ben's Linq to SQL Stored procedure vs Functions post of May 21, 2008 provides a detailed analysis of when to substitute user-defined functions (UDFs) for stored procedures in LINQ to SQL data-access scenarios.

Added: May 21, 2008

ASP.NET Dynamic Data Website Wizard Gets Major Overhaul in May 20 Update

Scott Hunter's May 20th Refresh of Dynamic Data is now Available post to the ASP.NET Forums of May 21, 2008 lists 11 significant changes to the Dynamic Data Website Wizard. An important upgrade is replacing details, edit, and insert ListView with FormView controls.

The Dynamic Data Runtime gets a few bug fixes, as well as UI and validation tweaks.

You can download the Dynamic Data Runtime and Templates from the MSDN Code gallery.

Added: May 21, 2008

Frans Bouma Red-Flags VB's Aggregate LINQ Reserved Word

According to his VB.NET: Beware of the 'Aggregate' keyword (updated) post of May 21, 2008, executing

Dim max = Aggregate o in metaData.Order Into m=Max(o.EmployeeID)

returns all Order entities and executes the Max() aggregate in the client's memory. Surprisingly, Frans reports in his update that the problem doesn't occur with DateTime or String values.

Added: May 21, 2008

Dean Whittaker Explains How to Use LINQ to SQL's DataContext Object to Recreate Test Databases

It's a common practice to mock database operations when using Test-Driven Development (TDD) to improve performance. If you don't mock the database, it's a good practice to recreate it each time your unit tests run to update it.

Dean Whittaker shows you how to do this in his Using Linq's DataContext to (re)create your database for testing post of May 21, 2008.

Added: May 21, 2008

Mike Taulty Extend's Julie Lerman's Analysis of EF Query Execution to LINQ to SQL

Mike's "When Do Queries Execute" post of May 21, 2008 extends Julie's discovery that stored procedures execute when invoked with ExecuteMethodCall() rather than when the data is needed (see below) to LINQ to SQL queries.

However, LINQ to SQL queries that invoke table-valued functions do so with CreateMethodCall(), which defers data retrieval until the data is required.

Added: May 21, 2008

Aaron Skonnard Describes the .NET 3.5 SP1 DataContractSerializer's New POCO and Cycle Capabilities

The Windows Communication Foundation (WCF) Data Contract Serializer (DCS) has two important new capbilities:

  1. Capability to serialize complete object graphs with associations that create cyclic references (a.k.a. bidirectional serialization or cycles) for services without a hack.
  2. Capability to serialize plain old CLR objects (POCOs) by removing the requirement to decorate classes with [DataContract] and [DataMember] attributes.

Aaron Skonnard takes on #1 in his DataContracts and object references post of May 14, 2008 and #2 in his detailed DataContracts without attributes (POCO support) in .NET 3.5 SP1 post of May 13, 2008. I missed Aaron's posts due to the activity surrounding release of .NET 3.5/VS 2008 SP1 Beta.

Prior to SP1, you could enable serializing graphs with cycles by setting the PreserveObjectReferences argument to true in the DCS's constructor. (Failing to do this raises an exception when the DCS encounters a cycle in the source object.)

However, you can't enable this option directly when you use the DCS with WCF in a service operation. Instead, you need to subclass DataContractSerializerOperationBehavior and override the CreateSerializer() method with the code described in Sowmy Srinivasan's seminal Preserving Object Reference in WCF post of March 26, 2006.

My LINQ to SQL and Entity Framework XML Serialization Issues with WCF - Part 1 post of October 9, 2007 and Serializing Cyclic LINQ to SQL References with WCF of October 30, 2007 cover issues with cycles in LINQ to SQL, which also apply to the Entity Data Model.

The latter post quotes a response to the System.ServiceModel.CommunicationException - The socket connection was aborted... question in the WCF forum by Microsoft's Ed Pinto:

Please be aware that there is no interop story for the preservation of object references.

I observed that "[t]he rumor is that Microsoft deliberately made it difficult to set this attribute value to discourage non-interoperable bidirectional serialization scenarios." It will be interesting to see if Microsoft has come up with an interop story to accompany SP1.

Added: May 21, 2008

Danny Simmons Updates Entity Framework FAQs

His New in version 0.5 of the FAQ… post of May 21, 2008 provides links to:

Added: May 21, 2008

Igor Ostrovsky Offers Seven Unusual Uses for LINQ to Objects

Igor is an infrequent poster but his 7 tricks to simplify your programs with LINQ entry of May 18, 2008 contains the following interesting examples:

  • Initialize an array
  • Iterate over multiple arrays in a single loop
  • Generate a random sequence
  • Generate a string
  • Convert sequences or collections
  • Convert a value to a sequence of length 1
  • Iterate over all subsets of a sequence

Thanks to Scott Guthrie for the heads-up.

Added: May 21, 2008

Matthieu Mezil Offers an Illustrated Introduction to Entity Framework with Advanced Topics

Matthieu's Entity Data Model Mapping: Beyond the Basics article for DataDeveloper.net starts by creating the requisite Northwind Entity Data Model with the Wizard, but then goes on to cover:

  • Many to many relationships
  • Entity splitting
  • Mapping with added conditions
  • Table Per Type (TPT) inheritance
  • Table Per Hierarchy (TPH) inheritance
  • Complex types
  • Create/update/delete SSDL functions
  • The SELECT SSDL function
  • Performing database operations based on views

Added: May 21, 2008

Matt Berseth AJAXifies the DetailsView of a Master/Details Web Form

Regardless of whether the page's DataGrid and DetailsView controls' data source is an ObjectDataSource, LinqDataSource or EntityDataSource, the AJAX Control Toolkit's ModalPopup with a DetailsView on an UpdatePanel improves the data editing experience.

Matt's Master-Detail with the GridView, DetailsView and ModalPopup Controls post of April 29, 2008 updates his prior version with a spiffed-up page design and now emulates saving changes to the back-end tables. Source code is available for download, and it's not much work to substitute a LinqDataSource or EntityDataSource for the ObjectDataSource.

Click here for a live demo.

If you're interested in AJAXifying DataGrids, read Matt's 7 simple steps to ajax-enable your ASP GridView

Thanks again to Scott Guthrie for the heads-up.

Added: May 21, 2008

Agnes Molnar Continues Her LINQ4SP Demonstrations

Hungarian SharePoint MVP Agnes Molnar (a.k.a. Aghy) shows her replacement for Bart DeSmet's LINQ to SharePoint implementation creating a lookup to a list in her LINQ4SP - How to create a new item with a lookup to another list? post of May 20, 2008. The post includes a link to a 02:30 silent screencast.

Ryan Hauert Updates an EF Three-Level Table per Hierarchy Entity with Stored Procs

Mapping ImportFunctions to stored procedures for updating base (Person) and inherited (Employee and Manager) types isn't a strictly intuitive process, so Ryan's Function Mapping with Inherited Types post of May 20, 2008 demonstrates the simplest approach, which is to create a single set of stored procedures for the base class and call them with wrapper functions in the SSDL file. A hitch in this process is that the wrapper functions are deleted each time you run the Update Database from Model operation.

Each wrapper changes the discriminator column value to conform to the level in the hierarchy, as discussed in the Re: Stored Procedures with Inheritance post of April 28, 2008 in the ADO.NET Entity Framework and LINQ to Entities (Prerelease) forum and David DeWitter's Entity Framework Stored Procedure Generation post of the same date..

Julie Lerman Discovers that EF Executes Stored Procs When Invoked, Not When Their Data is Needed

Her Command Execution of directly called ImportFunctions (stored procs) in Entity Framework post of May 20, 2008 explains the situation, which doesn't seem surprising to me.

ADO.NET Data Services to Add Replace Mode for Updates

In his Merge vs. Replace Semantics for Update Operations post of May 20, 2008, Pablo Castro announces that Astoria's current Merge update semantics will be complemented by a Replace option. Replace mode for the HTTP PUT method is required by the AtomPub spec.

The difference between the two modes is that Replace substitutes default property values for properties that aren't included in the uploaded message body's <Item> element, while Merge ignores missing properties. Missing links in Merge or Replace operations don't affect links on the server.

ADO.NET Team Offers Two New Entity Framework Web Casts

How Do I Get Started with the Entity Framework? (09:20)
In this introductory video, Alex James will show you how to build a simple Entity Data Model in a short amount of time.

How Do I Use the new EntityDataSource? (11:30)
In this introductory video Diego Vega will show you how to use the EntityDataSource in an ASP.NET Application.

SQL Server Compact 3.5 Runtime Bits Missing from VS 2008 SP1 Beta

SQL Server Compact 3.5 SP1 Beta and Synchronization Services for ADO.NET v1.0 SP1 Beta runtime bits didn't make it into the VS 2008 SP1 Beta package but you can download and install them from the preceding link.

Julie Lerman Takes on the Entity Framework Doubters

Julie posted this link to Bloglines citations of Danny's post in her Responses to Danny Simmons "Why Entity Framework" post of May 20, 2008.

Ironically, her post wasn't included in the Bloglines citation. (Several other cites in my Danny Simmons Answers the Frequently Asked Question: Why Use the Entity Framework? post were missing from Bloglines, too.)

Rob Conery Runs into a LINQ to SQL Corner with his Repository Model

He discovers "that if you set any Enumerable anything as a property, its Count property will be accessed when you load the parent object. This negates using any deferred loading for any POCOs, period." Yeah. That's run me nuts, too.

Update May 22, 2008: Scott Allen left a comment about Rob's preceding statement: "I'd say that requires more investigation. Doesn't sound correct." As it turns out, Scott did do some investigation and concluded that an IList<T> type change caused the overeager loading. See Rob's Not So Lazy MVC Storefront of 5/21/2008. 

Rob circumvents the problem by refactoring the MVC Storefront's Repository model, as described in his MVC Storefront: Intermission's Over, Made Some Changes post of May 19, 2008.

Update May 21, 2008: Rob clarifies the identity of his clients (the Microsoft ASP.NET team, the "community" and himself) in MVC Storefront: Client Progress Meeting of May 20, 2008, which details how the MVC Storefront project came to be at MIX 08 and his recent progress meeting with his boss, Shawn Burke.

Hopefully, it's time to go back to completing the code.

The SQL Server Data Service Team Breaks Their Silence

It's been a while since the last post from the SSDS folks. Soumitra Sengupta's What is going on at SQL Server Data Services of May 19, 2008 notes that SSDS is in the process of its second semi-monthly refresh after its introduction at MIX 08. Word on what new features, if any, the updates introduced will come some time after the refresh on May 20, 2008.

SSDS will be back in business by 9:00 AM on 5/21/2008.

SSDS documentation finally has been made public as the SQL Server Data Service Primer. The docs have some strange content, such as VS 2005 and .Net 3.0 being "recommended for Microsoft employees" to connect to SSDS. I recommend others use VS 2008 and .NET 3.5.

Update 5/21/2008: The SSDS team is Correcting an error in our documentation.

At MIX 07 the public beta was announced for July 2008. However, it's been pushed back two months to September 2008, according to Nigel Ellis's Introduction to New SQL Server Data Services: Web-Based Data Storage in a Cloud Web cast. I scheduled my Visual Studio Magazine article for the July issue to meet the original date; hopefully readers will be able to obtain a beta invitation if they aren't already "on-boarded" by July.

Mike Taulty Finds the Replacement for ADO.NET Data Services' DataWebKeyAttribute

Mike's ADO.NET Data Services and the Missing DataWebKeyAttribute post of May 19, 2008 explains that SP1 renamed it DataServicesKeyAttribute. This is consistent with the replacement of Web by Services in most class, method and property names.

If the Entity Framework back-end can't detect the table's primary key column you mus prefix the the class declaration with [DataServicesKey("ColumnName")] as mentioned in the ADO.Net Data Services Over LINQ to SQL? forum post.

Wally McClure Finds He Needs the Visual J# Redistributable to Get Meaningful Error Messages from ADO.NET Data Services

Strange, but apparently true, as Wally reports in ADO.NET Data Services in.NET 3.5 SP1 Beta1 of May 19, 2008. He promises a podcast about his Astoria experiences shortly.

Jon Skeet Gives Parallel LINQ a Workout with Nine Parallel LINQ (PLINQ) Mandelbrot Set Implementations

The Mandelbrot set is an ideal test bed for determining the efficiency of parallel processing algorithms and libraries. So Jon Skeet, C# MVP in the UK, decided to compare the performance of Parallel LINQ (PLINQ) with the Parallel Extensions (ParallelFx) with a variety of different approaches. The benchmarks are downloadable from his Mandelbrot revisited - benchmark edition post of May 18, 2008, which includes code samples and commentary.

Jon finds ParallelFx's ParallelForLoop implementation to have the best overall performance, but the PLINQ Unordered ParallelLinqInPlace approach wasn't far behind it.

Wednesday, March 26, 2008

LINQ and Entity Framework Posts for 3/24/2008+

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

Danny Simmons: Serializable Entity Framework Object Graphs Coming in Next CTP

Hidden in an innocuous "WCF & Entity Framework not working as expected" thread started on October 31, 2007 in the ADO.NET Entity Framework and LINQ to Entities (Pre-release) forum is this bombshell dated March 28, 2008:

[W]e realize that it would be nice to have graphs of entities just serialize by default without these kinds of gymnastics, but there are some hard problems with doing this using WCF in an interoperable way given that EF relationships are always bi-directional which means that EF always has graphs not trees and the cycles in graphs cause problems with the default WCF (DataContract) serializers.  Happily we've been working with the WCF team, and they came up with a great way to deal with this, so the next CTP of the EF will serialize entity graphs by default. [Emphasis added.]

If true, this new capability will obsolete Danny's EntityBag (Perseus) project. It wouldn't appear to eliminate the need for Ruurd Boeke's serialization to a lightweight client project, at least for Silverlight clients, but it might affect the market for IdeaBlade's DevForceEF product.

The inability of the DataContractSerializer to handle cyclic references appeared to be a major stumbling block to enabling an "out-of-the box multi-tier story" for LINQ to SQL. Hopefully, Matt Warren and his C# team will take another look at enabling n-tier deployment for LINQ to SQL projects.

Thanks to Julie Lerman for the head's up: Hallelujah - Entity Graphs will be XML serializable.

Added: 3/28/2008

Performance Problems Fixed for VB Queries with Filters Over Nullable Columns

Tim Ng reports in the VB Team's LINQ to SQL (and LINQ to Entities) performance improvements post of March 28, 2008 that LINQ to SQL and LINQ to Entities queries are "now smart enough to pass three-value logic from VB to SQL." This means you'll get

SELECT [t0].[CustomerID] 
FROM [dbo].[Orders] AS [t0] 
WHERE [t0].[EmployeeID] = @p0 
-- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [123]

instead of

SELECT [t0].[CustomerID] 
FROM [dbo].[Orders] AS [t0] 
WHERE (COALESCE( 
    (CASE 
        WHEN [t0].[EmployeeID] = @p0 THEN 1 
        WHEN NOT ([t0].[EmployeeID] = @p0) THEN 0 
        ELSE NULL 
     END),@p1)) = 1 
-- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [123] 
-- @p1: Input Int (Size = 0; Prec = 0; Scale = 0) [0]

when you filter on the nullable Orders.EmployeeID field.

Added: 3/28/2008

Ajax World: "Microsoft SSDS - Dumb Name, Brilliant Idea!"

Tim Negris' AjaxWorld Magazine article of March 17, 2008 has this deck: "A Google News search for Microsoft SSDS, the SQL Server Data Services it announced last week, yields just six articles." If Tim had broadened his search beyond New articles, he would have found hundreds of SSDS blog posts by March 17.

Tim explains the article's title:

To understand the potential impact of Microsoft's cloud strategy and SSDS service initiative on Oracle, IBM/DB2, Sun/MySQL, Ingres, Postgres and other relational or post-relational database management systems, it's important to note that SSDS has nothing to do with SQL. SQL Server Data Services is a dumb name because, while the service is apparently based at the storage level on Microsoft's SQL Server technology, it doesn't use SQL (Structured Query Language) or a variant of it to query the information in the database. It uses a new Microsoft language called LINQ.

He goes on to say:

LINQ enables full text search, page search, and presumably things like picture and audio search against items stored in the Microsoft SSDS database.

and notes earlier:

Keep in mind that "data" [stored by SSDS] can mean way more than inventory or contact records in columns and rows of text and numbers. Data can mean documents, e-mails and web pages, or music and video.

Neither of the preceding two excerpts are correct, at least for SSDS v1.

SSDS's only connection with AJAX that I can come up with is the promise of a JSON wire format for a future version.

Thanks to the SQL Server Data Services team for the heads-up: Interesting take from Rick Negris over at AjaxWorld magazine.

Added: 3/28/2008

Bryan Dawson Compares Performance of Entity Framework' eSQL and LINQ to Entities with SqlClient and T-SQL

Bryan follows up his two previous performance-related posts (Exploring Performance Part 1 of February 4, 2008 and Exploring Performance Part 2 of February 11, 2008) with ADO.NET Entity Framework Performance Comparison of March 27, 2008.

Bryan analyzes execution time of conventional and paging queries with no tracking for object queries. His graph shows the Entity Framework is about 4 to 5 times slower than SqlClient for paging queries. However, I believe Bryan's calculations are wrong for Entity SQL and LINQ to Entities paging queries.

My calculations, based on 100 tries with 64 ms. and 87 ms. for Entity Client and LINQ to Entities respectively appear in the Corrected column:

Query Type Standard Query Paging Query Corrected
SqlClient/T-SQL 4.0 ms 0.43 ms 0.43 ms
Entity SQL 6.0 ms 1.5 ms 0.64 ms
LINQ to Entities 7.5 ms 2.0 ms 0.87 ms

The ratios between execution times for Standard Query and Paging Query don't correspond, but Standard Query and Corrected ratios track closely.

Moral of this story: It pays to apply reasonableness tests before publishing performance results.

Added: 3/28/2008

Noam Ben-Ami Explains Simple Stored Procedure Mapping and Raises a Red Flag

Noam's Stored Procedure Mapping of March 26, 2008 (which appeared in the ADO.NET Team Blog on March 28) provides a script to create simple Product and Order tables as well as INSERT, UPDATE, and DELETE stored procedures for the Product table. Noam adds this caveat in his instructions:

At this point it is appropriate to note the first stumbling block: At this time, the Entity Framework requires you to map all three stored procedures. You cannot map only the delete stored procedure. In addition, the entity type must still be mapped to a table, view, or query view.

The requirement to map all three updated stored procedures is unadvertised but mentioned in a newsgroup post. Noam says the following about this requirement:

We hope to provide a solution for this issue in future versions of the Entity Framework, but for now, this is what needs to be done for associations whose target multiplicity, with respect to the type being mapped, is 1 or 0..1. In other words, the “reference” end of the association needs to be mapped to the keys of the target type.

I've never heard of a restriction that prevents executing update stored procedures against an Entity instance mapped to a FunctionImport. I've retested my initial test code that executes the INSERT, UPDATE and DELETE stored procedures and don't encounter a problem.

Added: 3/28/2008

Migrating to SQL Server Stored Procedures with the EDM Designer December CTP 2

Migrating the data source for Entity Framework (EF) EntitySets and AssociationSets from dynamic Entity SQL (eSQL) to dynamic SQL (T-SQL) commands to stored procedures (sprocs) with the Entity Data Model (EDM) Designer December CTP 2 isn't a walk in the park.

There's little in the way of official or unofficial documentation that specifies EF's requirments for supporting sprocs as data sources and data modification agents. What little information is available is buried in ADO.NET Team members' replies to a few users questions in the ADO.NET Entity Framework and LINQ to Entities (Pre-release) forum.

Earlier ADO.NET Team posts don't cover the EDM Designer's role in the process. For example, How to Map Stored Procedures using the ADO.NET Entity Framework of September 14, 2007 covered only the schema syntax and didn't discuss associations or updates. The earlier Using Stored Procedures for Change Processing in the ADO.NET Entity Framework of March 8, 2007 is more than a year old.

My Migrating to SQL Server Stored Procedures with the EDM Designer December CTP 2 post provides illustrated step-by-step instructions for moving the Products, Supplier, and Categories EntitySets from default eSQL queries and commands to a set of T-SQL stored procedures for EntitySet hydration and Entity instance updates, and covers mapping Associations as well as stored procedures for populating AssociationSets.

A future post will show the code required to test the migration.

Added: 3/27/2008

Ruurd Boeke Continues his Lightweight Client for the Entity Framework Project

The "Ruurd Boeke Plans a Entity Framework Variant with a Lightweight Client" topic of  LINQ and Entity Framework Posts for 3/17/2008+ describes Ruurd's objectives for a disconnected Entity Framework component with a lightweight client that can be used in a Silverlight project:

So, the end result should be an easy way to serialize and deserialize objects on the client and server, and a way to build up the object correctly on the server so it can be attached to the context again.

Ruurd's approach differs considerably from Danny Simmons' Perseus: Entity Framework EntityBag project on the MSDN Code Gallery, which I described in the "Retrieve and Update Entities Across Tiers with WCF and the EntityBag" sidebar for my "Model Domain Objects with the Entity Framework" for the March 2008 issue of Visual Studio Magazine.

His Relation support for n-tier EF post of March 27 provides code and message examples for serializing Entity updates with WCF's DataContractSerializer. You can compare his messages on the wire with those for Perseus that I described in my Logging EntityBag's SOAP Request and Response Messages post of January 29, 2008.

Ruurd concludes:

The API I have created is monstrous. Also, I think there are quite a few situations where this will break horribly.

Once I get just a little happier about it, I will do a screencast building a server using Entity Framework and a Silverlight client that is editing.

Added: 3/27/2008

Colin Meek: EF Extensions for Custom Stored Procedures with the Entity Framework

Colin, an EF developer, starts his new blog with ADO.Entity Framework: Stored Procedure Customization post of March 26, 2008 which provides documentation for the Entity Framework Extensions described in this week's "Entity Framework Extensions Library Available for Download from MSDN Code Gallery" topic.

His post describes how to use the extensions to simplify running arbitrary stored procedures and T-SQL commands as store commands against an ObjectContext, materialize them as objects, track changes, and deal with multiple result sets. The post describes the following coding patterns:

  • Creating and executing store commands
  • Materializing typed results
  • Tracking results
  • Multiple result sets

Alex James waxes enthusiastic about EF Extensions in his Colin Meek talks about his EF Extensions post of the same date:

Here is a little snippet that illustrates what is possible [with a typed materializer]:

var results = context
.CreateStoreCommand("GetCategories", CommandType.StoredProcedure)
.Materialize<Category>()
.Bind(categorySet);

What this does is execute the GetCategories stored proc, turning results into Category objects and binds them to the categorySet entityset so that changes can be tracked/managed by the Entity Framework.

Update 3/27/2008: Diego Vega adds more praise for the extensions in his Entity Framework Extensions (EFExtensions) Project available in CodeGallery post of March 27, 2008.

If you're populating entities with stored procedures, be sure to read Colin's post, download the EFExtensions and EFExtension Samples and give the sample project a test drive.

Added: 3/26/2008

Freek Leemhuis Scorns LINQ to SQL and Others Pile On

LINQ to SQL problems, which Freek posted on March 26, 2008, takes Anko Duizer's LINQ to SQL - TOP 5 of problems post of March 14, 2008, and contributes explanations of why Freek considers the following problems serious:

  1. LINQ to SQL is designed for a two tier scenario. LINQ to SQL does not fit natural[ly into] a multi layer architecture.
  2. It is not possible to tune the SQL Server queries generated by LINQ to SQL.
  3. LINQ to SQL generates dynamic SQL. The technology strongly motivates use [olf] dynamic SQL instead of stored procedures.
  4. LINQ to SQL encourages ... "SELECT *" quer[ies.]
  5. The cache mismatch problem. LINQ to SQL materialize[s] your objects "once" in the cache, this can give unexpected query results.

Paul Gielens adds #6 in his LINQ to SQL - TOP 5 + 1 of problems post of March 25:

#6 LINQ to SQL is intended for direct 1-1 mapping of a Microsoft SQL server database to .NET classes. LINQ to SQL is not a natural fit in typical enterprise scenarios.

LLBLGen's Frans Bouma pronounces judgment in his detailed comment to Paul's post:

Item 3, 4 and 5 for example are noise or wrong. ... Your #6 point is also noise, sorry :). ... Point 2 is valid.

and recites his usual litany of complaints about LINQ to SQL. Be sure to read the rest of the comments.

Note: Freek has written about LINQ to SQL previously. Click here for his posts tagged LINQ.

More Reasoned Views of LINQ to SQL Issues

Freek also includes a reference to Bob Beauchemin's MHO: LINQ to SQL and Entity Framework: Panacea or evil incarnate? Part 1 post of February 13, 2008. However, Bob generally debunked #2, #3, and #4 in this post. See the "Bob Beauchemin Starts a Series About LINQ to SQL and Entity Framework" of LINQ and Entity Framework Posts for 2/25/2008+.

Similarly, Bob's later posts offer rational evaluations of other topics. See the "Bob Beauchemin Addresses LINQ to SQL/Entity Framework Worry Points 4, 5 and 6" topic of LINQ and Entity Framework Posts for 3/6/2008+.

As to #1, LINQ to SQL fits without difficulty into a multi-layer architecture. The issue is its problems in with n-tier architecture. Keith Farmer made a strong point in his LINQ and 3-Tier Dogma post of November 6, 2007:

I know someone somewhere is going to accuse me of heresy for what I'm about to state, but it's something I've wanted to get off my chest for a couple years, since I first encountered LINQ to SQL, and started to realize what it meant...

The 3-Tier Model is just a pattern.

And, like all patterns,

It is meant to serve our needs, not the other way around.

Don't get hung up on academic concerns such as how many tiers you have in your system.  You'll just waste the time you could spend doing things you actually need to do.  Such as watching Avatar or playing Warcraft.

As evidenced by the amount of work being devoted to change tracking in disconnected (i.e., n-tier) scenarios, the n-tier issue might not remain for long.

Added: 3/26/2008

Matthew Hunter Updates LINQ to SQL Entity Base 1.0 to Beta 1.2

LINQ to SQL Entity Base 1.0 now supports change tracking for deletions and can perform cascade deletions. His New Version of LINQ to SQL Entity Base Class (Beta 1.2) post of March 26, 2008 adds:

I guess from my point of view it's feature complete for ASP.NET use, assuming you store the entities in the session.

Still have to work on serialization for WCF and other uses.

Here's the CodePlex link: LINQ to SQL Entity Base Class Version 1.0 Beta 2.0

The "Matt Hunter: Another Disconnected LINQ to SQL Project" topic provides more details on LINQ to SQL Entity Base.

Added: 3/26/2008

Update 3/28/2008: Implementing Deletion Change Tracking adds a SetAsChangeTrackingRoot() method to establish the baseline original values of an object and implements cascading deletions on the client.

Avi Wortzel Demonstrates a Complete Mock Object for LINQ to SQL

Israeli developer Avi Wortzel's Testing LINQ to SQL with Mock Object – a complete solution post of March 25, 2008 explains:

I decided to implement my own solution which includes two parts:

1. The ability to create database states [to] test the queries against ... (without the need of active SQL Server [o]n the air).

2. The ability to mock DML operations without actually execut[ing] them (and to create a database-less tests [= Tests that don’t have an active instance of SQL server to run]).

For the first part I used the Repository pattern (as the other guys suggested) and I referred the class which represent[s] the table as an in-memory one. It’ll give us the ability to query it with LINQ to Object. To achieve the second part I mocked the SubmitChanges() method from the DataContect class.

It appears to me to be a workable approach for removing SQL Server from the test loop. Avi's downloadable example uses Oren Eini's Rhino Mocks framework.

Added: 3/26/2008

Doug Rothaus: VB's XML Axis Properties and LINQ to XML for Accessing Descendent and Ancestor Elements

His VB XML Cookbook, Recipe 2: Descendants and Ancestors post of March 19, 2005, which didn't appear in the Visual Basic Team blog until March 25, "shows how you can access descendant and ancestor elements in an XML document using Visual Basic, XML Axis properties, and LINQ to XML objects."

Julie Lerman: Build Before Changing Entity Framework XML Files to Resources

Her Tip for working with embedded Ent. Framework models with Beta3 of March 25, 2008 explains Beta 3's problems with moving *.csdl, *.msl and *.ssdl files from the execution folder to project resources.

K. Scott Allen Explains Outer Joins with the LINQ GroupJoin Operator

Scott digs into creating the equivalent of SQL's LEFT OUTER JOIN with the LINQ GroupJoin, SelectMany, and DefaultIfAny operators in his Inner, Outer, Let's All Join Together With LINQ post of March 24, 2008.

Entity Framework Extensions Library Available for Download from MSDN Code Gallery

Colin Meek posted ADO.NET Entity Framework Extensions to the ADO.NET Entity Framework & LINQ to Relational Data section of the MSDN Code on March 24, 2008.

The undocumented extensions claim to simplify "various tasks in the Entity Framework including store command execution, entity state management and stored procedure mapping."

Update 3/26/2008: Documentation is available. See the "Colin Meek: EF Extensions for Custom Stored Procedures with the Entity Framework" topic.

Anything that simplifies stored procedure mapping is appreciated.

Thanks to Julie Lerman for the heads-up.

Live Demo of CSDL, MSL, and SSDL File Content for Entity Framework Inheritance and Other Scenarios

Asad Khan's downloadable Entity Framework Mapping Helper project from the MSDN Code Gallery is an interactive Windows form that displays the XML content of the CSDL, MSL, and SSDL layer for a variety of different scenarios. These include combinations of inheritance types (table per hiearchy, table per type, table per complex type, or mixtures of all three) with entity splitting, abstract types, complex types, and associations.

The project has self-contained *.csdl, *.msl and *.ssdl files for what appears to be a country club, so all you need to do is mark one of the inheritance check boxes and click the Display Mapping button to start.

Julie Lerman's EF Mapping Helper on Code Gallery post of March 24, 2008 provides a more detailed description and several screen captures of the Mapping Helper in action.

Andy Conrad: New Features in Store for ADO.NET Data Services V2

According to Andy's Astoria team is hiring! post of March 24, 2008:

We have positions open for Developers and Program Managers.  Currently, we are finishing up V1 and planning for V2, so it’s a great time to join the team.  For V2, we are thinking about expanding the project into new areas (e.g. offline support, sync, dynamic language support) so there will be plenty of new and exciting work.

Adding resources to the Astoria team also bodes well for its future as the on-premises version of SQL Server Data Services.

Eugenio Pace Continues His LitwareHR Series with Data Caching Episode

Eugenio ported the LitwareHR hosted multi-tenant demo app from SQL Server 2005 to SSDS, as described in his SQL Server Data Services - SSDS - New version of LitwareHR post during MIX 08.

His LitwareHR on SSDS - Part III - Data access enhancements 1: caching post of March 24, 2008 describes client-side caching at the Web services layer with a CacheManager (based on the Enterprise Library's caching block) and Repository to get and store cached and uncached items.

Here are links to earlier episodes:

The LitwareHR on SSDS - Part II - The data access layer post explains that the new client data model for SSDS implements an SSDS SOAP Client, ProxyFactory and Repository<T> stack, which replaces the previous SQL Server-based version's Data Access Application Block (DAAB) and MultiTenantDataAccess layer.

His LitwareHR on SSDS - Part I - Multi-tenancy & Flexibility post of March 14, 2008 explains SSDS's Authority-Container-Entity (ACE) storage architecture and how LitwareHR uses it to store individual Position and Resume entity sets for each tenant.

Justin Etheredge Continues Improvement to LINQ to Mock (Moq) Implementation for ASP.NET MVC

The Grouping expectation verification in Moq post of March 24, 2008 documents Justin's continued effort to use LINQ to Mock (a.k.a. Moq) to provide a complete mocking framework for the ASP.NET Model-View-Controller add-in.

Click here for more about LINQ to Moq and ASP.NET MVC, plus Justin's previous episodes.

LINQ to Firebird (Entity Framework Provider for Firebird) Is Progressing

Jiří Činčura's Entity Framework and Firebird (Part 2) post of March 24, 2008 describes the progress to date on creating an Entity Framework-enabled data provider for the Firebird open-source database (formerly Borland's InterBase RDBMS). The developer, jirka, says:

We're moving, slowly, step-by-step. And new functionality is coming in view. ... Yes, it's a "LINQ to Firebird", in fact LINQ to Entites connected to Firebird.

Here's the initial post of March 20, 2008: Entity Framework and Firebird.

Matt Hunter: Another Disconnected LINQ to SQL Project

Another from the How Did I Miss That? Department:

Matt released v1.0 Beta 1.1 of his LINQ to SQL Entity Base - Disconnected LINQ CodePlex project on March 20, 2008. Matt describes his project:

LINQ to SQL Entity Base is a simple base class that is primarily designed to support LINQ to SQL in a disconnected way, which is one of the shortcomings of the LINQ to SQL technology at the present time. This is highly useful in an n-Tier or ASP.NET environment where disconnected functionality is relavent.

LINQ to SQL Entity Base includes change tracking support in a "disconnected from data context" mode.

LINQ to SQL Entity Base also supports automated re-syncing of entities to a data context. This includes all entities under a entity tree which is basically all parent --> child type relationships.

There's more background information on LINQ to SQL Entity Base in Matt's .Net Blog for Software Developers blog.

Benjamin Eidelmann: A Disconnected LINQ to SQL Project

From the How Did I Miss That? Department:

Jose Marcenaro, Benjamin Eidelman and Ricardo de Guzmán of Argentine developer Tercer Planeta have posted the Unplugged LINQ to SQL Generator project (ULINQ) to CodePlex. Benjamin says:

Fitting the LINQ to SQL technology in your own N-tier application framework may require writing custom code for the entities.

This project implements a custom tool for generating code from a DBML model, which you may use instead of the default MSLinqToSQLGenerator in C# or VB projects.

Click here to read background details on the ULinqToSQLGenerator from the Tercer Planeta blog.

Saturday, March 22, 2008

LINQ and Entity Framework Posts for 3/17/2008+

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

Updated 3/22/2008 for confirmation that SSDS "will support the full EDM/EF/ADO.Net V3 model in due time," per Soumitra Sengupta. (That's the primary justification for including SSDS-related posts in this blog.)

Updated 3/23/2008 by adding Ruurd Boeke's Sneak preview: serializing objects with original values post of 5/17/2008 (missed), which adds information about the IEditableBusinessObject class, to the "Ruurd Boeke Plans a Entity Framework Variant with a Lightweight Client" topic.

David DeWinter Adds Dynamic Menu Commands to his LINQ to SQL Database Update Sync Project

Dave started a project in January 2008 to write a Visual Studio 2008 plug-in with capabilities to:

  1. Transform property names to be Pascal case
  2. Remove prefixes from the names of database objects
  3. Automate mapping the types of columns to various (developer-defined) enumerations

for LINQ to SQL projects.

The following posts supplement his source code in CodePlex's Entity Framework Contrib (EFContrib) section:

Added: 3/23/2008

Dave Robinson Posts Source Code for an Excel Add-in That Saves and Retrieves Worksheets to/from SSDS

Dave, who's the "new SSD blogger" I mentioned in the "New SQL Server Data Services Blogger and a Third-Party View of SSDS (et al.)" topic below, has written an Excel 2007 add-in that stored worksheet data to and retrieves it from a SQL Server Data Services container. His Using Excel with SSDS post of March 21, 2008 includes the SSDS-specific source code.

He promises a later post that demonstrates syncing data with the Microsoft Synchronization Framework.

Added: March 22, 2008

Beth Massi Plans Yet Another VB and XML Webcast on April 4, 2008

Beth's Live From RedBethmond: VB9 - Working with XML in Visual Basic post of March 21, 2008 gives the following description:

4/4/2008 9:00 AM Pacific Time (US & Canada) | Duration:60 Minutes
XML permeates every modern application today from XHTML, XAML, RSS, SOAP, Office Open XML just to name a few. Even your Visual Studio project files and configuration settings are XML files. The latest version of Visual Basic in Visual Studio 2008 supports a new language syntax aimed at making you much more productive when working with XML. In this Webcast we'll walk through language features like XML literals, embedded expressions and axis properties in order to create, query and transform XML with this powerful but easy to use syntax. Say goodbye to XSLT and hello to Visual Basic 9.

Added: March 22, 2008

The SQL Server Data Services Team Wants to Answer Your Questions about SSDS

Jeff Currier posted What questions do you have about SQL Server Data Services? on March 21, 2008. His post contains this question:

I've written several posts now around coding (in C# and in Java) about using SSDS.  So, I'm a bit curious if anyone out there has specific questions that either I (or others on team) might be able to answer.  This could be code related, design related, etc.  So, what questions do you have?

My questions were (paraphrased):

  1. How and when do you plan to support associations/relationships plus lazy/eager loading?
  2. How and when will applicants be notified of acceptance or rejection as beta invitees?
  3. What's the timeframe for adding the promised Atom/AtomPub format?

I probably should have omitted lazy loading from question #1.

Added: March 21, 2008

Update March 22, 2008 from Soumitra Sengupta in his Answering a few questions from Jeff's blog response to my questions:

1. What are your plans and timing for supporting associations/relationships plus lazy- and eager-loading?

Answer to the first question is that we will support the full EDM/EF/ADO.Net V3 model in due time.  It is a bit of work.  We do not have exact timing for it.  Once we do that we will have to address lazy and eager loading, right?

2. When will folks who signed up for the beta know if they've been accepted?

First batch should go out next week.  We will keep provisioning on a weekly basis from there on out.  By the way once the first batch gets provisioned, everyone else should be able to get to the technical documentation.

3. What's the schedule for an Atom/AtomPub implementation?

We are on this one.  Do not have the exact schedule to share at this time.

Good news on all but the timing of #3, but especially #1.

Soumitra's post also responds to questions from several other readers.

Ruurd Boeke Plans a Entity Framework Variant with a Lightweight Client

Ruurd's Progress on light objects on the client, full blown EF entities on the backend post of March 21, 2008 describes his work to date on an n-tier variation on the Entity Framework (EF) that eliminates the need to deploy the entity framework to the client tier. His objectives are:

What I want is one visual studio project: 'Domain' that holds business objects for me that I can use on both the client and the server. What I do not want, is to have to think about Entity Framework contexts on the client. Since I do not persist my objects on the client, I see no reason to actually create a context on the client, just to be able to do change tracking. Nor do I want to see any EF specific plumbing in the messages between that client and server: I lose interoperability if I do that. Also, if my client is Silverlight (for instance) I might not want to bring the EF assemblies over (if that's even possible?).

So, the end result should be an easy way to serialize and deserialize objects on the client and server, and a way to build up the object correctly on the server so it can be attached to the context again.

Updated 3/23/2008: The client objects will be implementations of Ruurd's IEditableBusinessObject interface, which he describes in his earlier Adding Edit support to businessobjects post of March 16, 2008 and Sneak preview: serializing objects with original values of March 17. The "Ruurd Boeke Adds Complex Types to His IPOCO Entity Framework Implementation" topic of LINQ and Entity Framework Posts for 3/10/2008+ contains links to his earlier Entity Framework posts.

The Sneak Preview poses describes his classes for serializing objects with original values:

EditableBusinessObject implements IEditableObject for you and also allows you to copy the currentvalues to a loadedvalues state.

CreateSerializeSurrogate generates a surrogate class that knows how to deal with loadedvalues and with circular references.

It appears to me that Ruurd's objectives are similar to those of IdeaBlade for their DevForce EF project, which is presently in beta. Ruurd's client is likely to be much lighter, which would make it more appropriate for deployment in a Silverlight project. However, IdeaBlade is hard at work on a Silverlight 2 client that uses a version of their existing DevForce framework (see below).

Added: March 21, 2008

IdeaBlade Posts 45-minute Screencast of their DevForce EF n-Tier Entity Framework Implemetation

You can play the Camtasia screencast from a link on IdeaBlade's main DevForce EF page. The product looks quite interesting to me. Both IdeaBlade and Ruurd Boeke avoid serializing and transporting the ObjectContext across process boundaries.

Thanks to Julie Lerman for the heads up on the video's availability.

My original post about DevForce EF was the "IdeaBlade Offers Downloadable Beta of DevForce Entity Framework" topic of LINQ and Entity Framework Posts for 3/10/2008+.

Added: March 21, 2008

Mike Taulty Writes an Essay On Disposing LINQ to SQL Data Contexts

Mike normally encloses his LINQ to SQL data access code in a Using block to ensure that it's disposed expeditiously, closes the SqlClient connection and returns it to the connection pool as quickly as possible. I do the same if I don't want to cache collections as a generic List in a WinForm or Silverlight project.

Unlike me, Mike decided to determine whether the Using block was necessary to close the connection immediately, rather than waiting for finalization.

Read Mike's LINQ to SQL and SqlConnection post of March 20, 2008 to learn what he discovered.

As a bonus, you can download the demo code from Mike's LINQ Talk at UK Visual Studio 2008 Launch. Mike's LINQ to SQL demo starts with:

using (DataContext ctx = new DataContext(
      "server=.;database=northwind;integrated security=sspi"))

Added: 3/20/2008

New SQL Server Data Services Blogger and a Third-Party View of SSDS (et al.)

"Life in the clouds..." is the name of David Robinson's new SSDS blog. Dave is a program manager for SSDS and plans to evangelize SSDS on The Code Trip at the University of Southern California on March 27, 2008 and the Microsoft Health & Life Sciences Developer and Solutions Conference 2008 on April 22-24. The following is from his first post:

What’s this blog all about you ask? Well it is going to be mostly focused on developing solutions on top of SSDS, but there will also be tidbits of other cool technology and an occasional rant or two.

Dave's most March 19 post points to Max Zilberman's SQL Server Data Services (SSDS) - a powerful proposition... post of March 18, 2008. Max, who works in Philadelphia as an Enterprise Software Architect for a Fortune 100 firm, says this about SSDS:

Many blogs have written about the nice bits announced at the MIX such as IE8, Silverlight Mobile, Silverlight 2.0 Beta, among others.   The session that was not given high level of attention, the SQL Data Services sent a really powerful message.

And goes on to explain why hosted data services make business sense.

Max also has nice things to say about ASP.NET Dynamic Data and ADO Entities - The new beginning.....

Added: 3/20/2008

An ASP.NET Model-View-Controller Tech Brief, Mock Frameworks and LINQ to Mock (Moq)

My ASP.NET MVC: Is the new MVC pattern right for you? TechBrief for Redmond Developer News' March 2008 issue points out that Scott Guthrie makes the following claim for ASP.NET's MVC feature:

.NET MVC ships with System.Web.IHttpRequest and IHttpResponse interfaces; this simplifies mocking the interfaces to deliver improved unit-test performance.

Scott Hanselman followed up his ASP.NET MVC Preview 2 session at MIX 08 with the ASP.NET MVC Session at Mix08, TDD and MvcMockHelpers post of March 7, 2008. This item includes MvcMockHelper source code for RhinoMocks, which Scott demonstrated in his session, Moq, a.k.a. LINQ to Mock, and TypeMock, a commercial framework. The helper code for all three frameworks is of similar complexity.

Scott had previously reviewed MOQ in his Moq: Linq, Lambdas and Predicates applied to Mock Objects of December 19, 2007, which starts with:

Kzu and friends have a new pet project called Moq, which may be the coolest derivative open source project name ever.

And ends with:

Slick. Moq is definitely a project to watch.

In between, Scott compares NMock, RhinoMock, TypeMock and Moq.

The "Daniel Cazzulino and Juan Wajnerman Create LINQ to Mock (Objects)" topic of LINQ and Entity Framework Posts for 12/17/2007+ has more details on the release of LINQ to Mock. (From the "Scott Hanselman Endorses LINQ to Mock (Moq)" topic of LINQ and Entity Framework Posts for 1/7/2008+.)

Kaz posted his Why do we need yet another NET mocking framework? essay on March 17, 2008. Justin Etheredge's Asp.net MVC Testing Imbalance of March 19, includes sample Moq code for a simple MVC Update action. Here's his complaint about the amount of mocking code required for a relatively simple unit test:

And that doesn't even include any of my helper objects or methods. Anyone see a problem with this? I am going to have to put some serious effort into streamlining this. I know that there is quite a bit I can abstract out across different controllers and actions so we will see how this goes.

I have the same problem with the mocking frameworks I've investigated. Regardless of the complexity issue, Moq is gaining well-deserved attention.

Updated 3/23/2008: Justin's Simplified Asp.net MVC Controller Testing with Moq of March 22, 2008 post simplifies the UserControllerUpdateTest() method by refactoring with helpers, such as CreateMockUserRepository() and CreateMockUserController() methods and a MockHttpContextContainer() class.

Added: 3/20/2008

Updated 3/21/2008: David Longnecker offers two posts on unit testing ASP.NET MVC projects: Exploring the ASP.NET MVC Preview 2 - First Glance and Exploring the ASP.NET MVC Preview 2 - Tests and Mocks, both of March 20 2008. The latter uses LINQ to Mock (Moq).

Eugenio Pace Continues His LitWareHR for SQL Server Data Services Saga

His LitwareHR on SSDS - Part II - The data access layer explains that the new client data model for SSDS implements an SSDS SOAP Client, ProxyFactory and Repository<T> stack, which replaces the previous SQL Server-based version's Data Access Application Block (DAAB) and MultiTenantDataAccess layer.

His entity-specific classes derive from the ExtensibleEntry base class, which provides the Id property required by SSDS, as well as Code and Location properties, which are common to all LitwareHR entities. His example contains a simple unit test to verify Insert() invocations by invoking an InsertKindGetByIdDelete() TestMethod.

The "Eugenio Pace Starts a Series on the LitwareHR Demo on SQL Server Data Services" topic of LINQ and Entity Framework Posts for 3/10/2008+ covers the first part of this series.

Added: 3/19/2008

Jimmy Bogard Finds XML-File Mapping Delivers Persistence Ignorance to LINQ to SQL Business Objects

Jimmy purchased a copy of LINQ in Action and discovered that you have four choices for mapping SQL Server tables to LINQ to SQL entities and associations:

  1. Visual Studio 2008's graphical O/R Designer
  2. The SqlMetal.exe command-line tool
  3. Custom class files you write to define entities with mapping by attributes you add to the classes and their properties
  4. A custom XML mapping file you create and process with SqlMetal.exe

He concludes that choice #4 provides persistence ignorance.

But his Mapping options in LINQ to SQL post of March 18, 2008 concludes:

For me, the final verdict is: Though LINQ to SQL gives me powerful strongly-typed querying abilities with LINQ, the only maintainable mapping option still pales in comparison to NHibernate.

Added: 3/19/2008

Jason Hunter Demos a Master/Detail Form with a SQL Server Data Services Back End

In his SSDS Patterns Part 1: Master/Detail in a Heterogeneous World post of March 18, 2008, Jason creates the classic Windows read-only master/detail form that displays a drop-down list of Customers, a DataGridView for Orders from the customer, and another DataGrid view of details (Lines) for the selected Order. He shows the minimal source code to populate the list and bind to the BindingSource controls for the DataGridViews to the objects created from the SQL Server Data Services (SSDS) entities with XML serialization code.

Jason, who's a dev lead in the SSDS group, promises his next post will demo "XML serialization to bridge the gap between SSDS and objects."

See the related "Jeff Currier Shows Source Code for SQL Server Data Services HttpRequest and HttpResponse Methods>" topic below.

Added: 3/18/2008

Danny Simmons: An Essay on Deleting Entity Framework Entities

Danny's Just delete it already! post of March 18, 2007 describes in detail why deleting a "fake" entity with associated entities in the data access layer requires more than just creating the entity and it's EntityKey, attaching it to the ObjectContext, and then invoking DeleteObject(). The incentive for faking an entity is saving a roundtrip to the data store to retrieve it.

You must have access to the associated entities so you can delete their AssociationSets in the process. This means you must execute an ObjectQuery to retrieve them. In this case, you might as well retrieve the entity from the data store, because it will retrieve the entity of interest and its associated objects (as the "relationship span") with a single query.

Deleting many:1 EntitySets for AssociationSets represented in the store by nullable foreign key values isn't a problem. In this case, the generated SQL statement just sets the foreign-key value to null. Deletions become more complicated when associations are required by specifying NOT NULL foreign key values in the database. Deleting 1:many EntityReferences isn't a problem whether they're required or not; cascading deletion simply removes the dependent entities associated with the deleted parent along with the relation.

More about issues with deleting many:1 EntityRefs for required AssociationSets will follow.

Added: 3/18/2008

Greg Duncan Insists on Stored Procedures for Production LINQ to SQL Queries

Greg is Development Manager/Primary Developer for KMPG's Electronic Data Discovery (EDD) product line. Greg describes EDD as

Taking "electronic data" (files, emails in PST/NSF's,etc) gathering metadata, deduping, converting to PDF/Tiff/JPG and exporting for loading into litigation support systems.

His LINQ to SQL NOLOCK'ing post of March 18, 2008 includes a quote from Scott Hanselman's Getting LINQ to SQL and LINQ to Entities to use NOLOCK post of March 17, 2007, which suggests replacing the NOLOCK hint for queries with TransactionScope and System.Transactions.IsolationLevel.ReadUncommitted. Either prevents long-running transactions from blocking reads but can lead to retrieving inconsistent data.

Greg says "I use the NOLOCK hint in my SQL 2000 world a bit" and goes on to say:

Now that said, I'm still not going to "endorse" LINQ to SQL for production usage yet at work, UNLESS our existing stored procedures (or new SP's) are used. And you know what? SP's work nicely with LINQ to SQL. I was able to drop some tables into the design surface, drag over some SP's, set some properties and I was LINQ'ing quite well. Select, inserts and updates working easily all the time through our SP's. There were quite a few "oh that's just cool" moments.

Why SP's? Because they have saved my bacon a number of times over the years (I've been coding against SQL Server since 4.21a...). Practical real world experience has re-enforced my belief in SP's as my primary DB level API. Not a religious thing, just an experience thing...

LINQ to SQL's graphic designer makes substituting stored procedures (sprocs) for parameterized dynamic T-SQL in CRUD operations easy, but doing the same in Entity Framework involves manually editing the SSDL and MSL files with Visual Studio 2007's (or another) XML Editor. The XML editor has schemas for *.edmx, *.csdl, and *.ssdl files to support IntelliSense, but not for *.msl files. Mapping and testing sprocs for associations/relationships is an agonizing process.

The Stored Procedure Support (Entity Framework) online help topic for ADO.NET Entity Framework Beta 3 provides simple examples. See the ADO.NET Team's "Using Stored Procedures for Change Processing in the ADO.NET Entity Framework" post of March 8, 2007 and "How to Map Stored Procedures using the ADO.NET Entity Framework" post of September 14, 2007 by Mike Dodaro for examples with more detailed explanations.

If you're working with Entity Framework and your DBA insists on stored procedures for updates, you might try getting an exemption by explaining the mapping issues involved.

Added: 3/18/2008

Jim Wooley Explains LINQ Joins on Composite Keys

In Joining composite keys with LINQ of 3/17/2008, Jim observes that

[T]he Join extension method does not support the ability to provide the InnerKeySelector/OuterKeySelector as a series of expressions.

But the solution isn't obvious. Here's his VB expression for a join on City + State composite key:

Dim query1 = _
    From l In dc.LendingLimits _
    Join p In dc.Properties _
    On New With {l.County, l.State} Equals _
          New With {p.County, p.State} _
    Where p.PropertyId = SearchValue And _
          l.EffectiveDate = TargetDate _
    Select l.Amount

Cool!

Added: 3/18/2008

Rob Conery Waxes Enthusiastic over Lambda Functions

Rob appears to have fallen in love with Lambdas. As he says in his My Personal Lambda Crusade post of March 17, 2008:

I love lambdas and I’m pretty sure they solve every problem imaginable. Why just the other day my daughter painted her face with leopard spots, using a Sharpie pen, and I said to myself "Rob(x=>x.Beer("immediately"))" and all of a sudden the world was a brighter place…

His post includes a link to "a very good read." It's Howard Dierking's Lambda, Lambda, Lambda! post of January 18, 2008, which has one of the best explanations of an expression tree I've ever come across. Howard's the Editor-in-Chief of (and tech lead for) MSDN Magazine.

Added: 3/18/2008

Jeff Currier Shows Source Code for SQL Server Data Services HttpRequest and HttpResponse Methods

Jeff's Some SQL Server Data Services Coding Examples post of March 16, 2008 include C# samples for making RESTful HttpRequest.CreateRequest calls that accept URI, HttpMethod, data, and contentType parameters, as well as and reading responses with a custom ReadResponse(HttpWebResponse) method that returns the data as a string.

A more user-friendly version requests and returns a list of an Authority's Containers that Jeff imports into a LINQ to XML XDocument and binds it to an ASP.NET dropdown list. He then constructs a query of the selected Container and binds a list of entities with Kind = Customers to a GridView control.

Jeff promises to post a similar demo for SOAP request and response messages as well as for Java.

(Jeff's originally from the WinFS group. His first blog post is a recommendation to catch the "DAT416  Building on WinFS: Developing a Great WinFS App from Scratch" session from Tech*Ed 2006!)

Ruurd Boeke Describes How to Build an Entity Data Model Client without an Entity Framework Reference

His Adding Edit support to businessobjects post of March 16, 2008 says:

I'm building toward a set of tools that will enable me to use EntityFramework on the server and use the same businessobjects on the client-side, without having to reference EntityFramework at all.

This first post implements an IEditableBusinessObject, which inherits from IEditableObject. Ruurd uses PostSharp's OnFieldAccessAspect to intercept properties and add their values to the statebag. His "next step will be to get this [object] to serialize nicely, with original values and such."

For more background on the EDM server side, see the "Ruurd Boeke Adds Complex Types to His IPOCO Entity Framework Implementation" topic of LINQ and Entity Framework Posts for 3/10/2008+.