Sunday, June 22, 2008

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

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

Steve Gentile Posts a Brief Account of His First Brush with Silverlight 2 Beta 2 Databinding to LINQ to SQL

In his Stepping into Silverlight… post of June 21, 2008, Steve test-drives Silverlight 2 databinding to LINQ to SQL with the assistance of the Swiss MSDN tutorials, specifically the Silverlight 2 Beta1 + WCF + LINQ to SQL = a powerfull combination video of March 17, 2008. The Swiss sample is available for download as an attachment to the post.

Be sure to read Steve’s tips in his second update.

Added: 6/22/2008 1610 PDT

Soumitra Sengupta Explains Why There Are No Docs for Full-Text Search Over SQL Server Data Services

I included a note in the “Soumitra Sengupta: SQL Server Data Services Targeting Sprint 3 Update in a Week or Two” topic below about missing docs for SSDS’s new full-text search (FTS) feature. Soumitra clears up my Confusion about Full Text Search in SSDS on June 22, 2008, in which he quoted my note (without attribution).

It turns out he was speaking about adding FTS to the back end, with exposure by the front-end web service to follow. He then said, “So from now on when I talk about new features, I will just talk about features that are accessible through SSDS webservice to avoid confusion.”

I second Mike Amundsen’s comment:

Hey, it's fully understandable that you have 'back-end' and 'front-end' rollouts that might be 'out-of-sync' from the user perspective. But *please* keep us posted on both aspects, OK? 

Knowing that an item is in the back-end, even if it means we'll need to wait a bit before it's exposed to clients, is still interesting news.

A more open approach such as Pablo Castro uses for Astoria might be more effective:

This post is part of the transparent design exercise in the Astoria Team. To understand how it works and how your feedback will be used please look at this post.

(Mike and I have known each other for many years.)

Added: 6/22/2008 1115 PDT

Jeff Currier Describes Use of ETags and the HEAD Method for Managing Concurrency Issues with SQL Server Data Services

Jeff’s ETag's, Optimistic Concurrency and SSDS post of June 22, 2008 describes the role of HTTP ETag header values as timestamp equivalents in RESTful updates to SQL Server Data Services (SSDS) entities. Updating an entity increments its numeric Version value, so the the Version attribute value is used as the ETag for conditional, single-entity GET, PUT, and DELETE method invocations. Jeff says ETags aren’t applicable to query operations because they can return multiple entities.

He also mentions that SSDS will support the HEAD method, which just returns specified header values. This permits lightweight client-side comparison of server ETag values without performing an operation on the data.

Added: 6/22/2008

Steve Naughton Completes His Database Based Permisions Series for ASP.NET Dynamic Data and Posts the Source Code

His DynamicData: Database Based Permissions – Part 4 adds attribute-based permissions to consume the database-based metadata.

This post includes links to download source code for SQL Server 2005 and 2008 versions.

Added: 6/21/2008 1710 PDT

Steve Naughton Uses the InMemoryMetadataProvider to Add Runtime Permissions for ASP.NET Dynamic Data

Steve’s DynamicData: Database Based Permissions - Part 3 takes advantage of Marcin Dobosz’s InMemoryMetadataManager to apply TablePermissionAttributes and and TableColumnAttributes.

Added: 6/21/2008

ADO.NET Team’s Mike Kaufman Starts Four-Part Series about Options for Entity Data Model Tools

Mike observes in his EDM Tools | Options (Part 1 of 4) post of June 20, 20008:

Internally, the Data Programmability team refers to a set of these [CSDL, MSL, SSDL] files as “c/m/s files”. The EDM Tools Team made a decision [to] simplify the VS experience by aggregating the c/m/s files into a single .edmx file. The unfortunate state of affairs for V1 is that EdmGen.exe and the Entity Framework APIs [System.Data.Entity.Design] that ship in the .NET runtime can’t read EDMX files.

Here’s a brief description of the contents of the four episodes:

  1. Difference in file formats between the Visual Studio tools and the Entity Framework APIs in the .Net Framework
  2. Generating models from a database and code from a model
  3. Validating models and mappings
  4. EdmGen2.exe: A command-line tool that understands how to read and write the EDMX file formats and can replace the original EdmGen2.exe

Full source code for EdmGen2.exe is available from the MSDN Code Gallery.

Added: 6/21/2008

Sanjay Nagamangalam Demonstrates How to Use a T4 Template to Generate Entity Framework Views

Sanjay’s Using a T4 template for View Generation post of June 20, 2008, shows you how to use the Text Template Transformation Toolkit in VS 2008 with the or templates from an enclosure to his post to generate precompiled Entity Framework views.

The advantage of compiling views is reducing the initial startup time of a session. Moving from using EdmGen.exe to the prebuilt T4 template solves several problems and simplifies the process.

Be sure to read the tips at the end of Sanjay’s post before you test-drive his tutorial.

Added: 6/20/2008 1400 PDT

Troy Magennis Analyzes LINQ to Objects Aggregate Functions’ Response to Special Cases

Troy Magennis, the curator of the Hooked on LINQ wiki, started a new blog that contained a LINQ over Objects Aggregate Functions Special Case Table post of October 3, 2006. I hadn’t seen it when Troy posted it and found it still interesting today. The table provides responses of Sum(), Min() an Max() operators to null source, empty source, source with >0 nulls, and source with all nulls conditions for all common CLR numeric data types.

Added: 6/20/2008

ADO.NET Team Posts New EntityDataSource Tutorial for ASP.NET Data Controls

Eric Dettinger, an Entity Framework SDET, posted Tutorial: Entity Data Source Control on June 18, 2008. The illustrated, step-by-step tutorial uses the AdventureWorks database to create a three-level (Categories, SubCategories, and Products) with EntityDataSource components populating a Web app with three linked DataGrid controls.

Added: 6/19/2008 1820 PDT

Steve Naughton Adds a User Interface to Modify His New Database-Based Permissions

The steps involved in moving from Steve’s original application design to handle role-based permissions in the database that acts as the persistence store are:

    1. Create the database tables.
    2. Add a User Interface to modify the permissions.
    3. User Marcin's InMemoryMetadataProvider to add the database based permissions to the Metadata at runtime.
    4. Add components from A DynamicData Attribute Based Permission Solution using User Roles to consume the database based metadata.

Steve’s DynamicData: Database Based Permissions - Part 2 post of 9/19/2008 covers step 2.

The “Steve Naughton Starts Database-Based Permissions Series for ASP.NET Dynamic Data” topic covers step 1.

Added: 6/19/2008 1210 PDT

David Robinson Distills SQL Server Data Services Best Practices from His Tech*Ed 2008 Sessions

Dave’s Best Practice - Data Partitioning post of June 18, 2008 deals with data partitioning over authorities and containers. Data partitioning was one of the topics of his “Best Practices in Building Applications with Microsoft SQL Server Data Services” presentation at Tech*Ed 2008 Developer and IT Pro.

Using a Movie Showtimes application, he partitions the data into western and eastern authorities which he specifies to be located in western and eastern datacenters. (The current beta allows only one authority per participant and specifying location isn’t supported.)

Dave’s recommendations:

  • Take advantage of the Geo-Location aspect of Authorities
    • Choose an authority closest to your users
  • Take maximum advantage of Containers
    • Containers are placed on individual nodes
    • Partitioning your data across containers maximizes your throughput on Query and CRUD operations.

Added: 6/19/2008

David Ebbo: ASP.NET Dynamic Data’s Support for Data Sources Other Than LinqDataSource or EntityDataSource

In his Using ASP.NET Dynamic Data with ObjectDataSource post of June 18, 2008, Dave notes that VS 2008 SP1’s Dynamic Data feature supports LINQ to SQL and Entity Framework data sources by default and will work with other data sources that support LINQ and provide a data context object that defines each EntitySet by a class.

By taking advantage of the Dynamic Data Extensions (see the “David Ebbo: ASP.NET Dynamic Data Extensions and Samples Added to CodePlex” topic below), you can back Dynamic Data with a traditional combination of an entity class, business logic layer, and ObjectDataSource component.

The post contains a screen capture of a demo app with IntegerSlider and DateAjaxCalendar controls.

Added: 6/19/2008

Marcelo Lopez Ruiz Delivers a Lecture About .NET Mutability with a Brief Astoria Punchline

The upshot of Marcelo’s Mutability in the .NET Framework post of June 18, 2008 is the same as his prior two posts about ADO.NET Data Services: Initialize your service. He concludes:

[T]he object that you get is mutable while InitializeService is executing, but once it's finished, it becomes read-only. … This is all part of the work done to ensure that the security and metadata settings initialized through the configuration 'stick' to the service across all requests and provide a uniform interface to callers.

Added: 6/19/2008

Rob Conery Demonstrates the Repository Pattern for Improving Testability of Data-Backed Apps

Rob’s SubSonic: Writing Decoupled, Testable Code With SubSonic 2.1 post of June 18, 2008 doesn’t have much to do with SubSonic. He creates a SubSonicMVC solution with four projects:

  • ASP.NET MVC Website
  • Data Access Project (Class Library)
  • Business Logic (Class Library)
  • Test Project (using MS Test)

For data access with Northwind, he creates a Product class, an ICatalogRepository interface with a GetProducts() method of the IList<Product> type, and implements the interface with SubSonic. His tests use Dependency Injection (DI) to substitute a SubSonicCatalogRepository for a stub TestCatalogRepository when needed.

In short, a brief, very welcome example of implementing a testable, layered Web app with a repository and DI.

Added: 6/19/2008

Aaron Erickson Updates i4o (Indexes for Objects) to Support Plain Old CLR Objects (POCOs)

According to Aaron, i4o Release 0.92 Beta 2 of June 8, 2008 “addresses performance improvements, supports POCO, and rounds out of features needed for release.” It also has the following changes:

    • Added capabilities for dynamic indexing that allows creation and management of indexes on the fly.
    • Added support for vb string comparisons in the expression evaluator.
    • Added unit test suite (>90% code coverage)

Added: 6/19/2008 Edited: 6/23/2008

Soumitra Sengupta: SQL Server Data Services Targeting Sprint 3 Update in a Week or Two

Recovered from Orlando’s heat and humidity, Soumitra posted SSDS at TechEd 2008 on June 18, 2008. The post primarily chronicles happenings at the two Tech*Ed 2008 conferences, which others on the team covered earlier. The interesting item in his postblog was the following:

On the execution front, we are close to finishing Sprint 3.  We are now in ASK MODE for bug fixing - which means we need explicit permission from shiproom to take a fix.  Should be done with this in a week or two.  I will post the new feature set as soon as we release to operations.  Will be back when that happens. [Emphasis added.]

In the meantime, I’m waiting for the docs to try full-text search, which was part of Sprint 2. It’s not over until … the docs are done.

Added: 6/18/2008 1430 PDT

David Ebbo: Updated ASP.NET Dynamic Data Core Bits Moved from MSDN Code Gallery to CodePlex

David’s ASP.NET Dynamic Data on CodePlex post of June 18, 2008 announces that ASP.NET Dynamic Data’s “core” components have moved to Dynamic Data Runtime and Templates 5-23a on CodePlex’s aspnet project pages. He comments that:

Once Framework 3.5 SP1 officially ships, there will no longer be a need for this.  Note that for all practical purpose, this update is identical to what the final release will be in SP1.  We are now completely locked down, and have not made a change in 3 weeks.  It just takes a little more time for the whole VS SP1 stack to finish up and be out the door. [Emphasis David’s]

David Ebbo: ASP.NET Dynamic Data Extensions and Samples Added to CodePlex

The same ASP.NET Dynamic Data on CodePlex post of June 18, 2008 announces the availability of ASP.NET Dynamic Data Extensions from CodePlex. This is an upgrade to the Dynamic Data Samples, which remain available for download.

Here’s David’s description of the Extensions and Samples contained in the 1.4 MB .zip file:

[T]hese Extensions are basically a big VS solution that contain both a library of new features (Microsoft.Web.DynamicData.Extensions.dll), and a couple web sites that show them in action.

  • It gives us a place to experiment with new features that we didn't have time to put in SP1.  Some of those will eventually make their way into the next version of Dynamic Data, while others are likely to remain samples.  Obviously, we'd love to get feedback on those (the forum is the right place for that).
  • It lets us address some issues that are in the SP1 release and couldn't be fixed in time.
  • It has some great samples for Dynamic Data users to look at and learn how to achieve various results.  Note that a few of the samples that were previously separate are now included in there (e.g. Scott Hunter's DbImage sample).

The 'Extensions' project is very much work in progress, and we are actively adding things to it.  So you should expect to see fairly frequent updates on CodePlex.

And the “official” description on CodePlex:

The Dynamic Data Extensions is buildable sample that contains many of the new ideas we are thinking about building into Dynamic Data version 2.0. This project is available in source format and builds a Microsoft.Web.DynamicData.Extensions.dll that can be used to add this new functionality into an existing Dynamic Data website.

Here are some of the items you will find in the project:

  • Have fields in the control that display images from the database
  • Support for Insert pages grabbing their default value from filters
  • Support for Astoria
  • Support for binding to plain CLR objects
  • Support for ObjectDataSource
  • Localized displayname and description attributes
  • Add metadata to objects at runtime
  • Advanced filters (autocomplete, cascading)
  • FieldTemplate for Enum columns

Important: To test the Extensions library’s features, compile DynamicDataExtensions.csproj to create the assembly, and then compile and run the DynamicDataExtensionsSamples.sln project to display a page that explains and displays an example of each extension.

Scott Hunter Updates ASP.NET Dynamic Data DbImage Sample

Scott originally posted his Sample for Displaying Images from the Database using Dynamic Data on January 14, 2008 and announced that he updated it to the current ASP.NET Dynamic Data version (5-23a preview) in his Dynamic Data DbImage Sample Updated post of June 17, 2008.

The updated version is included in the ASP.NET Dynamic Data Extensions package on CodePlex described above and available as an independent download here. Scott says the updates include these changes:

  • Fixed an issue that caused DbImage not to work when the primary column for the table is a GUID.
  • Added support for compound primary keys (primary key that is more then one column in the table).
  • Added support for Entity Framework (previous release would display images in Entity Framework but fail to update them).
  • Added a helper method to the sample that disables partial rendering for UpdatePanels when the DbImage type is detected so images render correctly.

Here’s a capture of half of the Categories EntitySet with modified Site.css styles:

Ryan Dunn Starts a Working with Objects in SQL Server Data Services Series

Ryan’s Working with Objects in SSDS Part 1 of June 17, 2008 describes a process for overcoming a problem with missing xsi:type declarations when serializing objects in the Plain Old XML (POX) format used by the REST protocol of SQL Server Data Services (SSDS). He noted the problem in his earlier Serialization in SSDS post of May 28, 2008.

Here’s an example of a serialized Northwind Order entity with the required xsi:type=”x:dataType” attributes generated by the sample code for my forthcoming Visual Studio Magazine article:

<Order xmlns:s="" xmlns:xsi="" xmlns:x="">
  <OrderID xsi:type="x:decimal">10302</OrderID>
  <CustomerID xsi:type="x:string">SUPRD</CustomerID>
  <EmployeeID xsi:type="x:decimal">4</EmployeeID>
  <OrderDate xsi:type="x:dateTime">1996-09-10T00:00:00</OrderDate>
  <RequiredDate xsi:type="x:dateTime">1996-10-08T00:00:00</RequiredDate>
  <ShippedDate xsi:type="x:dateTime">1996-10-09T00:00:00</ShippedDate>
  <ShipVia xsi:type="x:decimal">2</ShipVia>
  <Freight xsi:type="x:decimal">6.2700</Freight>
  <ShipName xsi:type="x:string">Suprêmes délices</ShipName>
  <ShipAddress xsi:type="x:string">Boulevard Tirou, 255</ShipAddress>
  <ShipCity xsi:type="x:string">Charleroi</ShipCity>
  <ShipRegion xsi:type="x:string"></ShipRegion>
  <ShipPostalCode xsi:type="x:string">B-6000</ShipPostalCode>
  <ShipCountry xsi:type="x:string">Belgium</ShipCountry>

(The article is the “Test-Drive SQL Server Data Services” cover story for the July 2008 issue.)

I had the same problem as Ryan, so I used LINQ to XML’s functional construction rather than an XmlSerializer to generate the POX from a SqlDataReader.

Ryan’s new approach is to create a generic wrapper (SsdsEntity<T>) for arbitrary Plain Old CLR Objects (POCOs). Ryan observes that the limitations of his approach are:

    • We are limited to the same datatypes that SSDS supports.  This also means nested objects and arrays are not directly supported.
    • We have lost a little of the 'flexible' in the Flexible Entity (the E in the ACE model).  We now have a rigid schema defined by SSDS metadata and T public properties and enforced on our objects.

Ryan promises in his next post to “attempt to address some of those limitations and … introduce a library that handles most of this for you.”

Off-Topic: Google App Engine Has Serious Reliability Problems

According to TechCrunch’s June 17, 2008 Google App Engine Goes Down and Stays Down post:

Google hasn’t responded yet to a request for comment, although they did post a brief message on the Google Groups site for App Engine:

We’ve experienced several outages during the past 12 hours, the most recent of which started at 6:30am PDT and is still ongoing. During these outages, a significant percentage of requests resulted in errors. The errors are related to usage of the Datastore. We’re working hard to determine the cause of these outages and will continue updating as we make progress.

Nothing on the Google App Engine blog yet.

Stuff like this tends to make developers nervous about adopting a new platform.

Update: It’s back up!

Jesse Robbins’ Service Monitoring Dashboards are mandatory for production services! post of June 17 on O’Reilly Radar makes the following suggestions:

  • If you launch a platform that people pay you money for, you need to have a real time service dashboard. Ideally this should be decoupled from the rest of your infrastructure.
  • Don't rely on platforms that lack service monitoring dashboards for production.

Don Dodge, leader of Microsoft’s Emerging Business Team, posted Amazon, Twitter, Disqus down. Do you really want your data in the cloud? on June 7, 2008.