Monday, December 01, 2008

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

Note: This post is updated daily or more frequently, depending on the availability of new articles.
Updated 12/1/2008 4:30 PM PST
Updated 11/27/2008 9:00 AM PST
               • Updated 11/26/2008 9:00 AM PST

Entity Framework and Entity Data Model (EF/EDM)

Julie Lerman’s Calling UDFs from Entity Framework - Not what you might have expected post of 11/29/2008 describes how EF handles SQL Server’s user-defined functions, which you must call directly from the SSDL with Entity SQL, unless they return an entity instead of a scalar value.

Boincer asks “So does SDS work with .Net's Entity Framework at all?” is his SDS and Entity Framework thread of 11/29/2008 in the SQL Data Services (SDS) - Getting Started forum. Microsoft’s Anil Reddy responds:

We continue to work on this as we speak. I cannot mention the timeline, but we should have the functionality that you mention exposed very soon. [Emphasis added.]

Support for EF depends on implementing schemas for SDS entities, which the SSDS team has been promising for many months. It probably depends also on implementing the AtomPub wire protocol, the goal of this incubation project:

Accessing SDS using ADO.NET Data Services - This incubation project focuses on aligning SDS and ADO.NET Data Services. With this alignment SDS will support AtomPub and JSON formats. It will also provide support for established set of conventions for constructing URLs to point to resources. We are also extending ADO.NET Data Services to provide access to the flexible data stored in SDS.

Note: Disregard the incorrect Codename “Astoria” – Online article title; that’s a separate incubator project.

Kristofer Andersson’s Tools - Part 7 - Add-ins - How to deal with the Entity Framework designer and orphaned entities post of 11/27/2008 describes the beta version of a new EDMX Cleanup feature added to the Huagati DBML/EDMX Tools that …

will assist with cleaning up orphaned entitysets/entitytypes without the need for an xml editor. The first version supports creating CSDL equivalents from orphaned SSDL entities, or alternatively dropping orphaned SSDL. Creating SSDL/dropping CSDL will be added in the next version.

You can download a copy of v1.49 the beta here.

His Offtopic: Thanksgiving, the turkey holiday… article offers a Thai-flavored recipe for roast turkey stuffed with pineapple, which has enzymes that act as a meat tenderizer, and a link to his wife’s recipe for Thai Left-over Turkey Curry.

Julie Lerman shares my reservations (see below) about Srikanth Mandai’s approach to sub-dividing EDMs by adding <Using> elements in her CSDL's Using Construct for Big Models post of 11/26/2008. I wouldn’t be surprised to see Kristofer Andersson tackle this problem in a future DBML/EDMX Tools update.

Beth Massi interviews Milind Lele in the Drag-Drop Data Binding Comes to WPF in Visual Studio 2010 Channel9 video of 11/26/2008. Milind demonstrates drag-and-drop data-binding an Entity Data Model for Northwind’s Customers and Orders tables to a WPF master-details form. The feature is coming in VS 2010.

Matthieu Mezil asks How to delete all the related entities? and answers his question in a brief 11/26/2008 post.

Srikanth Mandadi’s Working With Large Models In Entity Framework – Part 2 post of 11/26/2008 suggests “Sub-dividing the model into smaller models with type reuse,” which has the following shortcomings:

  1. No designer support: The designer does not support “Using”. So you would have to create your model first using designer and then edit the xml to use Entities from a related model.
  2. Bi-Directional Navigation Not Supported: Since you cannot create cycles when creating model dependencies, you can declare navigation properties only in one model.

These two limitations are likely to make this approach unpopular.

Matthieu Mezil observes in his EF: Attach a graph post of 11/25/2008:

In a lot of cases (WCF scenario for example) we need to attach a graph to a context. But the graph can be modified when it is detached. So you have to apply modifications when you attach it back. To do this, ObjectContext class has a method ApplyPropertyChanges. This method only applies to the scalar properties, so it’s insufficient for graphs. …

In fact, in a WCF scenario for example, you never get the same ObjectContext. So to delete an entity, it means that you need to load it from DB to delete it then. In this case, I prefer to use a SSDL Function (which can be a DB stored procedure) to delete it directly with just the entity key.

He then goes on to provide the source code for a static AttachExtension class which supports most modification cases.

Ido Flatow asks What does Entity Framework has to do with MSBuild? (11/24/2008) and provides his own answer:

The answer to the above question should be “nothing, unless you’re trying to build a project that references entity framework”, but apparently it isn’t so.

He supplies the solution (adding an <assemblyBinding> group to the config file) to running the project with .NET 3.5 as the target framework.

Srikanth Mandadi’s Working With Large Models In Entity Framework – Part 1 post of 11/24/2008 acknowledges the performance problems that occur when EF’s Entity Data Model reaches 50 to 100 tables. Metadata load and view generation times increase roughly in proportion to the number of tables and the number of interconnections between the tables. The post notes that you can reduce view generation time by pre-compiling the view, but the only practical method of reducing metadata load time is to split the model.

Alex James want EF users and trainers to stop referring to the EDMX file as the Entity Data Model (EDM) in his EDM misconceptions post of 11/24/2008. But he does acknowledge that the ADO.NET Team is at least partially responsible for the confusion by using the EDMX file extension.


Kristofer Andersson tackles set-based delete operations in his Architecture - Linq-to-SQL and set-based operations: Delete statements post of 11/25/2008, which is a follow-on to his earlier post about set-based update statements: Architecture - Linq-to-SQL and set-based operations: Update statements of 11/5/2008. Kris notes:

Microsoft’s Bart de Smet (author of the B# blog) also recognized the need for language integrated set-based operations in his “Dude, where’s my LINQ DML” blog entry. Although his article left out the actual implementation - he’s instead elaborating on a generic interface to front this functionality. (Although I have to say that I think my implementation results in more clean end-user code than his suggested interface. I know I’m abusing lambdas for the “set”-part but I think it is clear enough anyway…).

See below for a copy of last week’s post about Bart’s article.

••• Visual Studio Magazine’s “Speed O/R Mapping with LINQ to SQL” cover story by Roger Jennings for the December 2008 issue carries the following deck:

LINQ to SQL continues to be a top contender in the .NET object/relational mapping tool market despite Microsoft's promotion of the Entity Framework as one of the "Pillars of SQL Server 2008: Dynamic Development."

The article includes a table that compares LINQ to SQL and Entity Framework features and a “Visual Studio 2008 SP1 Add-Ins Remove LINQ to SQL Roadblocks” sidebar that describes Huageti Systems’ DBML/EDMX Tools utility for LINQ to SQL and Entity Framework and Damien Guard’s T4 template for customizing LINQ to SQL partial class code generation.

The LINQ to SQL Featured in Visual Studio Magazine’s December 2008 Cover Story post of 11/24/2008 adds related OakLeaf blog links and a couple of minor corrections to the text and table. (Repeated from LINQ and Entity Framework Posts for 11/17/2008+.)

Bart De Smet’s Dude, Where’s My LINQ DML? post of 11/22/2008 discusses adding DML for “batch updates that don’t require client-side input or computation.” Bart demonstrates attempts at “Updateable LINQ to Objects,” “Updateable remotable LINQ,” and “Introducing IUpdateable<T>”, but bails with the following:

I’ll leave a concrete implementation of an update provider to the inspired reader; a basic prototype for SQL (only allowing columns to be updated with constant string or integer values) worked like a charm.

(Repeated from LINQ and Entity Framework Posts for 11/17/2008+.)

LINQ to Objects, LINQ to XML, et al.

Justin Etheredge proposes Taking the Magic out of Expression<T> in his 11/29/2008 post, which provides a easy-to-read introduction to the implementation of expression trees in C# 3.0.

LinqMaster’s Yield Statement in C# post of 11/26/2008 explains how the Yield statement relates to iterators for LINQ collections that implement IEnumerable.

ADO.NET Data Services (Astoria)

Simon Segal concludes in his REST Vs. SOAP - Is the writing on the wall for WSDL & SOAP? post of 11/27/2008 that:

A lot of excitement seems to be being generated [at Microsoft] around REST and remarks like “keep using SOAP and WSDL if it works for you and your comfortable with it”, only seem to support that notion that the focus is shifting.

ASP.NET Dynamic Data (DD)

Vincent Home explains why Dynamic Data is an important development in his Dynamic Data a Nutshell post of 11/29/2008 and links to Scott Hanselman’s earlier Putting ASP.NET Dynamic Data into Context post of 4/10/2008, which offers a more complete analysis.

David Ebbo’s Fun with T4 templates and Dynamic Data post of 11/26/2008 continues the trend started by Damien Guard and Danny Simmons toward code-generation with T4 templates for data-driven projects. David’s template automates getting started with a DD custom page by replacing the FormView with a DetailsView and adding a DynamicControl for each field. The template works with both LINQ to SQL and Entity Framework data sources.

Steve Naughton also updated Dynamic Data Compound Column *** UPDATED 2008/11/08 *** again on 11/26/2008.

Steve Naughton’s DynamicData - Automatic Column Update For Entity Framework post of 11/26/2008 is an update to his earlier Automatic Column Update post of 5/25/2008.

David Ebbo demonstrates Using User Controls as Page Templates in Dynamic Data with or without routing in this 11/25/2008 post, which includes downloadable code.

SQL Data Services (SDS) and Cloud Computing

••• Jeff Barr’s Amazon SimpleDB Grows Up post of 12/1/2008 announces that Amazon Web Service’s SimpleDB database service has moved from private to public beta status with a substantial reduction in data storage fees (from $1.50/GB-month down to $0.25/GB-month). Jeff says:

We've made the business decision to go with SimpleDB even simpler than it was before. You can now get started for free. For at least the next six months, you can consume up to 500 MB of storage, and you can use up to 25 machine hours each month. You can transfer 1 GB of data in, and another 1 GB out. You can move as much data to and from Amazon EC2 as you would like, for free.

I’m in the process of writing and testing an ASP.NET test harness for SimpleDB that emulates the Azure test harness described in my seven-part Azure Storage Services Test Harness series. Currently, I’m testing it locally, which emulates the Azure version’s local Web hosting with Azure data.  Later this week, I’ll test hosting the ASP.NET project on EC2, which very closely resembles an Azure production environment. Another version that’s hosted on EC2 and uses the EC2 instance’s SQL Server Express engine as the data source is operational.

Note: I’m finding some strange behavior of the QueryWithAttributesResult class returning attributes in an unexpected sequence and an issue with the use of the QueryWithAttributesRequest’s sort operator in query expressions. More details will follow this week.

••• Mike Amundsen’s SDS Feature Wish List of 11/30/2008 lists his request for added HTTP protocol features. Mike says:

You might notice that most of the requests I list here relate to 'application protocol' level items - HTTP. That's because I am currently most interested in these issues and I have not found too many others covering the same space. I know there are lots of important database-related features that SDS can include, too.

••• George Reese presents security issues with Amazon Web Services that also apply, at least in part, to the Azure Services Platform and Google App Engine in his Key Security Issues for the Amazon Cloud post of 11/30/2008 and his earlier Twenty Rules for Amazon Cloud Security post of 11/27/2008.

Steve Marx’s Deleting Entities from Windows Azure Without Querying First post of 11/29/2008 shows you how to directly delete entities whose composite primary key values you know. Direct deletion saves a server round trip.

Mike Levy asks How "expensive" is it to create a queue? in an 11/29/2008 thread in the Windows Azure forum. Microsoft’s Daniel C. Wang replies that the resource cost is approximately the same as creating a blog container, which he considers “cheap.” Determining the economic cost remains in the dark until Microsoft announces pricing for Azure Queue Services.

Ken Church, Albert Greenberg, and James Hamilton analyze micro- versus mega-datacenters in their On Delivering Embarrassingly Distributed Cloud Services paper presented at the Seventh ACM Conference on Hot Topics in Networks (Hotnets 2008), 10/6-7/2008 in Calgary. In many cases, especially e-mail processing, geodisperse server “condos” holding 48 servers are more cost-effective than tier II+ datacenters housing 54,000 servers. (You can read all conference papers in this 20-MB PDF file.)

Boincer asks “So does SDS work with .Net's Entity Framework at all?” is his SDS and Entity Framework thread of 11/29/2008. See the EF/EDM section for Microsoft’s reply.

Michael Arrington’s Live Cashback Having A Bad Black Friday post of 11/28/2008 observes that “users are reporting that [Microsoft’s Live Cashback site] has been down much of [Friday] morning, and more than half of my attempts to connect are timing out.” He points out:

It’s also not so great for Microsoft’s expanding cloud computing efforts. If Microsoft can’t keep their own sites live on heavy traffic days, they can’t expect other companies to have faith in them as a platform either.

There’s a bit more more about the outage in Rajat Taneja’s Black Friday cashback blackout post to the Live Search blog of 12/1/2008.

Mike Amundsen describes updates to his SDS Provisioning Client in his Sample SDS Web Client Updated thread of 11/26/2008 in the Windows Azure forum. The new release “includes the ability to display the SDS metrics for authorities and containers as well as an option to view the "raw" SDS responses for all queries.” 

Stuart Lodge’s A fix for the Azure TableStorageMemberProvider post of 11/26/2008 solves this bug, a providerKey is generated but is never actually stored in the table storage, by adding a single line of code. Microsoft’s Frank Siegemund says the bug is a known issue in the Simple fix for ProviderUserKey in TableStorageMembershipProvider in the SDK samples thread of the Windows Azure forum and provides source code for the current method.

Steve Marx followed up on an earlier post (see below) with his Windows Azure Worker Role to Deal with Spam post of 11/25/2008. The post includes a live link to test Steve’s anti-spam implementation.

Scott Watermasysk’s Cloud Options - Amazon, Google, & Microsoft post of 11/25/2008 compares the features of the three major cloud computing platforms. Scott gives the Azure Services Platform props for background processing (not available with the Google App Engine), “super-simple deployment,” and staging. Dare Obasanjo gives Scott’s post high marks in his A Comparison of Amazon, Google and Microsoft's Cloud Computing Offerings post of the same date.

Jon Udell’s IronPython/Azure status report of 11/25/2008 doesn’t paint a rosy picture for using IronPython in the cloud. Windows Azure’s security model currently prevents importing even pure Python modules. Jon did manage to get Sriram Krishnan’s Python module, “which wraps the RESTful interface to Azure blobs,” by exchanging Python’s minidom, httplib, time, and base64 modules with their .NET equivalents.

Steven Levy says on page 7 of his Ray Ozzie Wants to Push Microsoft Back Into Startup Mode cover article of 11/24/2008 for Wired Magazine’s December 2008 issue:

The Ozzie project that must deliver results is Microsoft's so-called operating system for the cloud. As more apps become Web-based, the raison d'être for Windows—running programs on desktop PCs—becomes less compelling. What better way to make up for the decreasing importance of a desktop operating system than to create a dominant OS that runs services in the cloud? This is not only a crucial effort but one in which Microsoft is playing catch-up: went live with its cloud services in early 2006 and now hosts data storage or applications for more than 400,000 developers, including the complete historical archives of The New York Times. Google's entire company is based on the premise that people want to move from desktop to cumulus. But Microsoft hopes to use its cloud OS (codenamed Red Dog, now called Windows Azure) to dominate the cloud the way DOS and Windows did the desktop. [Emphasis Levy’s.]

He then goes on to deliver additional background on the Red Dog project and Live Mesh.

Lori MacVittie’s Cloud Computing: Vertical Scalability is Still Your Problem post of 11/24/2008 discusses issues with vertical, rather than horizontal scalability. Her definitions:

Horizontal scalability is the ability of an application to be scaled up to meet demand through replication and the distribution of requests across a pool or farm of servers. It's the traditional load balanced model, and it's an integral component of cloud computing environments.

Vertical scalability is the ability of an application to scale under load; to maintain performance levels as the number of concurrent requests increases.

Lori suggests “Things you can do to improve vertical scalability

  1. Optimize SQL / database queries
  2. Take advantage of offload capabilities of application delivery solutions available
  3. Be aware of the impact on performance and scalability of decomposing applications into too finely grained services
  4. Remember that API usage will impact vertical scalability
  5. Understand the bottlenecks associated with the programming language(s) used and address them”

Steve Marx demonstrates Adding a Property (Column) in Windows Azure Tables (11/24/2008) by adding UserIP, UserAgent, Referrer, and IsSpam properties (attributes) to the BlogComment entity of his blogging application with a flexible schema. Steve notes that local Developer Storage runs on a SQL Server 200x Express instance, so his method only applies to instances running on Azure’s cloud storage.

LiquidBoy’s  How do you make a Container's content read-accessible to the public? thread started 11/24/2008 in the SQL Data Services (SDS) - Getting Started forum elicited a reply from the SDS Team’s Rick Negrin:

We do not have that capability today.  The only way to access a container is using the username and password for the account that owns that container. So unless you give out your password no one else can access it. This is something we are looking to implement in the future.

As Ryan Dunn notes in another reply, Azure Data Storage services and the Windows Azure OS enable public access to applications, tables, blobs, and messages.

SQL Server Compact (SSCE) 3.5 and Sync Services

Steve Lasker’s Demos, Presentations, Links, Screencasts and Videos for SQL Server Compact post of 11/25/2008 covers his recent presentations at PDC and Tech Ed:

His extraordinarily long post also includes links to many SSCE and Sync Services demo projects and other related resources.

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

Simon Segal’s ASP.Net only for line of business? [Silverlight baby, Silverlight - Part 1] post of 11/24/2008 discusses the issues developers face when deciding which new technologies to adopt and his decision to take on development of a Silverlight 2 project. You can download the project’s initial UI here.

Microsoft announces availability of the Microsoft Web Platform Installer (Release Candidate), which installs Visual Web Developer 2008 Express Edition, SQL Server 2008 Express Edition, Visual Studio Tools for Silverlight, latest ASP.NET MVC beta and the .NET Framework 3.5 SP1 on Windows Vista RTM, Windows Vista SP1, Windows XP, Windows Server 2003, Windows Server 2008. The OS support added in the RC makes it ideal for installing these packages on an Amazon EC3 Windows Server 2003 instance.

Eric White adds Query Composition using Functional Programming Techniques in VB 9.0 in his Functional Programming Tutorial for Visual Basic 9.0 post of 11/24/2008 to his earlier Query Composition using Functional Programming Techniques in C# 3.0. Eric says:

The examples are converted to Visual Basic, and I’ve adjusted some topics to accommodate the differences between Visual Basic and C#. As with the C# tutorial, I've targeted it towards VB developers who have no functional programming experience.