Monday, August 04, 2008

Comparison of Code and T-SQL Queries for LINQ to SQL and Entity Framework Databound Forms

The Drag-and-Drop Master/Details Windows Forms Still Missing from Entity Framework SP1 Beta post of August 4, 2008 describes the need for sample code to demonstrate that drag-and-drop databinding with promised post-Visual Studio 2008 SP1 Beta improvements is as effective as that of LINQ to SQL for common usage patterns, such as fully editable master/detail/subdetail forms.

Note: This post will be updated shortly with code to change Product EntityRef[erence]s. 

LINQ to SQL Master/Detail/Subdetail Form Example

LINQ to SQL query execution for Customers/Orders/Order_Details form with the last five Orders and their Order_Details items displayed for a selected customer:

private void MainForm_Load(object sender, EventArgs e)
{
    ctxNwind = new NorthwindDataContext();
    DataLoadOptions options = new DataLoadOptions();
    // Load only the last five orders, newest first
    options.AssociateWith<Customer>(c => c.Orders.
        OrderByDescending(o => o.OrderDate).Take(5));
    options.LoadWith<Order>(o => o.Order_Details);
    ctxNwind.LoadOptions = options;
    customerBindingSource.DataSource = ctxNwind.Customers;
    employeeBindingSource.DataSource = ctxNwind.Employees;
    shipperBindingSource.DataSource = ctxNwind.Shippers;
    productBindingSource.DataSource = ctxNwind.Products;
    cboCustomer.DataSource = ctxNwind.Customers;
    cboCustomer.DisplayMember = "CustomerID";
}

The following four T-SQL batches run on startup to populate ComboBox and ComboBoxColumn lists:

SELECT [t0].[CustomerID], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactTitle], [t0].[Address], [t0].[City], [t0].[Region], [t0].[PostalCode], [t0].[Country], [t0].[Phone], [t0].[Fax]
FROM [dbo].[Customers] AS [t0]
SELECT [t0].[EmployeeID], [t0].[LastName], [t0].[FirstName], [t0].[Title], [t0].[TitleOfCourtesy], [t0].[BirthDate], [t0].[HireDate], [t0].[Address], [t0].[City], [t0].[Region], [t0].[PostalCode], [t0].[Country], [t0].[HomePhone], [t0].[Extension], [t0].[Photo], [t0].[Notes], [t0].[ReportsTo], [t0].[PhotoPath]
FROM [dbo].[Employees] AS [t0]
SELECT [t0].[ShipperID], [t0].[CompanyName], [t0].[Phone]
FROM [dbo].[Shippers] AS [t0]
SELECT [t0].[ProductID], [t0].[ProductName], [t0].[SupplierID], [t0].[CategoryID], [t0].[QuantityPerUnit], [t0].[UnitPrice], [t0].[UnitsInStock], [t0].[UnitsOnOrder], [t0].[ReorderLevel], [t0].[Discontinued]
FROM [dbo].[Products] AS [t0]
The following executes on startup and the first time the user selects a customer other than the first:
exec sp_executesql N'SELECT TOP (5) [t0].[OrderID], [t0].[CustomerID], [t0].[EmployeeID], [t0].[OrderDate], [t0].[RequiredDate], [t0].[ShippedDate], [t0].[ShipVia], [t0].[Freight], [t0].[ShipName], [t0].[ShipAddress], [t0].[ShipCity], [t0].[ShipRegion], [t0].[ShipPostalCode], [t0].[ShipCountry]
FROM [dbo].[Orders] AS [t0]
WHERE [t0].[CustomerID] = ((
    SELECT [t2].[CustomerID]
    FROM (
        SELECT TOP (1) [t1].[CustomerID]
        FROM [dbo].[Customers] AS [t1]
        WHERE [t1].[CustomerID] = @p0
        ) AS [t2]
    ))
ORDER BY [t0].[OrderDate] DESC',N'@p0 nvarchar(5)',@p0=N'ALFKI'

The following query runs up to five times (depending on the number of orders for the customer) after the preceding query:

exec sp_executesql N'SELECT [t0].[OrderID], [t0].[ProductID], [t0].[UnitPrice], [t0].[Quantity], [t0].[Discount]
FROM [dbo].[Order Details] AS [t0]
WHERE [t0].[OrderID] = @x1',N'@x1 int',@x1=11087

and @x1=11011, 10952, 10835, 10702 for ALFKI.

Another Customers query runs at this point for unknown reasons.

Note 1: Changes to Salesperson (EmployeeID) and ShipVia (ShipperID) don’t affect the Order entity until changes are saved and data is refreshed.

Note 2: You can’t edit the ProductID value of an Order_Detail entity because it’s a member of the composite primary key. You must delete and recreate the entity.

Entity Framework v1 SP1 Beta Emulated Master/Details/Subdetails Form Example

Entity Framework query execution for Customers/Orders/Order_Details form with last five orders and details displayed for selected customer.

The following code loads the data sources for the ComboBox and ComboBoxColumns and calls event handlers to fill the Orders and Order_Details DataGridViews with the first customer’s last five orders:

private void MainForm_Load(object sender, EventArgs e)
{
    ctxNwind = new NorthwindEntities();
    customerBindingSource.DataSource = ctxNwind.Customers.ToList<Customer>();
    employeeBindingSource.DataSource = ctxNwind.Employees.ToList<Employee>();
    shipperBindingSource.DataSource = ctxNwind.Shippers.ToList<Shipper>();
    productBindingSource.DataSource = ctxNwind.Products.ToList<Product>();
    isLoaded = true;
    customerBindingSource.MoveFirst();
    customerBindingSource_CurrentChanged(null, null);
    // Reset AllowNew = true to add a pending new order
    orderBindingSource.AllowNew = true;
    cboCustomer.DataSource = ctxNwind.Customers;
    cboCustomer.DisplayMember = "CustomerID";
}
The orderBindingSource.AllowNew reset is required to enable adding a new order. Without resetting the property value, you can’t add a new order from the UI or with the orderBindingSource.New() method because the ObjectBindingSources.Items collection has become fixed-size. The instruction must be at this particular location in the code to prevent loss of the ComboBoxColumn’s selection.
The following two methods synchronize Orders and Order_Details with Customer and Order selections:
// Emulate behavior of OrdersBindingSource = CustomersBindingSource
// with Orders.DataMember = "Orders"
private void customerBindingSource_CurrentChanged(object sender, EventArgs e)
{
    if (isLoaded)
    {
        // Get the current Customer instance
        Customer cust = (Customer)customerBindingSource.Current;
        // Attach the Orders and Order_Details 
        cust.Orders.Attach(cust.Orders.CreateSourceQuery().
            OrderByDescending(o => o.OrderDate).Take(5));
        foreach (Order o in cust.Orders)
            o.Order_Details.Attach(o.Order_Details.CreateSourceQuery().
                Where(d => d.OrderID == o.OrderID));

        // Get the Customer’s associated Orders
        orderBindingSource.DataSource = 
            cust.Orders.Where(o => o.Customer.CustomerID == cust.CustomerID);
        orderBindingSource.MoveFirst();
        int row = 0;
        foreach (Order ord in orderBindingSource)
        {
            // Provide foreign-key values for SalesPerson and ShipVia ComboBoxes
            orderDataGridView.Rows[row].Cells[1].Value = ord.Employee.EmployeeID;
            orderDataGridView.Rows[row].Cells[5].Value = ord.Shipper.ShipperID;
            row++;
        }
        // Bind Order_Details to the first Order
        orderBindingSource_CurrentChanged(null, null);
    }
}
// Emulate behavior of Order_Details Binding Source = OrdersBindingSource
// with Order_Details.DataMember = "Order_Details" (called by highlighted line above)
private void orderBindingSource_CurrentChanged(object sender, EventArgs e)
{
    Order order = (Order)orderBindingSource.Current;
    if (order != null)
        order_DetailBindingSource.DataSource = order.Order_Details;
}
The following four T-SQL batches run on startup to populate ComboBox and ComboBoxColumn lists (similar to LINQ to SQL batches):
SELECT 
[Extent1].[CustomerID] AS [CustomerID], [Extent1].[CompanyName] AS [CompanyName], 
[Extent1].[ContactName] AS [ContactName], [Extent1].[ContactTitle] AS [ContactTitle], 
[Extent1].[Address] AS [Address], [Extent1].[City] AS [City], 
[Extent1].[Region] AS [Region], [Extent1].[PostalCode] AS [PostalCode], 
[Extent1].[Country] AS [Country], [Extent1].[Phone] AS [Phone], [Extent1].[Fax] AS [Fax]
FROM [dbo].[Customers] AS [Extent1]
SELECT 1 AS [C1], 
[Extent1].[EmployeeID] AS [EmployeeID], [Extent1].[LastName] AS [LastName], 
[Extent1].[FirstName] AS [FirstName], [Extent1].[Title] AS [Title], 
[Extent1].[TitleOfCourtesy] AS [TitleOfCourtesy], [Extent1].[BirthDate] AS [BirthDate], 
[Extent1].[HireDate] AS [HireDate], [Extent1].[Address] AS [Address], 
[Extent1].[City] AS [City], [Extent1].[Region] AS [Region], 
[Extent1].[PostalCode] AS [PostalCode], [Extent1].[Country] AS [Country], 
[Extent1].[HomePhone] AS [HomePhone], [Extent1].[Extension] AS [Extension], 
[Extent1].[Photo] AS [Photo], [Extent1].[Notes] AS [Notes], 
[Extent1].[PhotoPath] AS [PhotoPath], [Extent1].[ReportsTo] AS [ReportsTo]
FROM [dbo].[Employees] AS [Extent1]
SELECT 
[Extent1].[ShipperID] AS [ShipperID], [Extent1].[CompanyName] AS [CompanyName], 
[Extent1].[Phone] AS [Phone]
FROM [dbo].[Shippers] AS [Extent1]
SELECT 
1 AS [C1], 
[Extent1].[ProductID] AS [ProductID], [Extent1].[ProductName] AS [ProductName], 
[Extent1].[QuantityPerUnit] AS [QuantityPerUnit], [Extent1].[UnitPrice] AS [UnitPrice], 
[Extent1].[UnitsInStock] AS [UnitsInStock], [Extent1].[UnitsOnOrder] AS [UnitsOnOrder], 
[Extent1].[ReorderLevel] AS [ReorderLevel], [Extent1].[Discontinued] AS [Discontinued], 
[Extent1].[CategoryID] AS [CategoryID], [Extent1].[SupplierID] AS [SupplierID]
FROM [dbo].[Products] AS [Extent1]

The following executes on startup and the first time the user selects a customer other than the first:

exec sp_executesql N'SELECT TOP (5) 
[Project1].[C1] AS [C1], 
[Project1].[OrderID] AS [OrderID], [Project1].[OrderDate] AS [OrderDate], 
[Project1].[RequiredDate] AS [RequiredDate], [Project1].[ShippedDate] AS [ShippedDate], 
[Project1].[Freight] AS [Freight], [Project1].[ShipName] AS [ShipName], 
[Project1].[ShipAddress] AS [ShipAddress], [Project1].[ShipCity] AS [ShipCity], 
[Project1].[ShipRegion] AS [ShipRegion], 
[Project1].[ShipPostalCode] AS [ShipPostalCode], 
[Project1].[ShipCountry] AS [ShipCountry], [Project1].[CustomerID] AS [CustomerID], 
[Project1].[EmployeeID] AS [EmployeeID], [Project1].[ShipVia] AS [ShipVia]
FROM ( SELECT 
    [Extent1].[OrderID] AS [OrderID], [Extent1].[CustomerID] AS [CustomerID], 
    [Extent1].[EmployeeID] AS [EmployeeID], [Extent1].[OrderDate] AS [OrderDate], 
    [Extent1].[RequiredDate] AS [RequiredDate], 
    [Extent1].[ShippedDate] AS [ShippedDate], [Extent1].[ShipVia] AS [ShipVia], 
    [Extent1].[Freight] AS [Freight], [Extent1].[ShipName] AS [ShipName], 
    [Extent1].[ShipAddress] AS [ShipAddress], [Extent1].[ShipCity] AS [ShipCity], 
    [Extent1].[ShipRegion] AS [ShipRegion], 
    [Extent1].[ShipPostalCode] AS [ShipPostalCode], 
    [Extent1].[ShipCountry] AS [ShipCountry], 
    1 AS [C1]
    FROM [dbo].[Orders] AS [Extent1]
    WHERE ([Extent1].[CustomerID] IS NOT NULL) AND ([Extent1].[CustomerID] = @EntityKeyValue1))  AS [Project1]
ORDER BY [Project1].[OrderDate] DESC',N'@EntityKeyValue1 nchar(5)',@EntityKeyValue1=N'ALFKI'

Like LINQ to SQL, the following query runs up to five times (depending on the number of orders for the customer) after the preceding query:

exec sp_executesql N'SELECT 
1 AS [C1], 
[Extent1].[OrderID] AS [OrderID], [Extent1].[ProductID] AS [ProductID], 
[Extent1].[UnitPrice] AS [UnitPrice], [Extent1].[Quantity] AS [Quantity], 
[Extent1].[Discount] AS [Discount]
FROM [dbo].[Order Details] AS [Extent1]
WHERE ([Extent1].[OrderID] = @EntityKeyValue1) AND ([Extent1].[OrderID] = @p__linq__1)',N'@EntityKeyValue1 int,@p__linq__1 int',@EntityKeyValue1=11087,@p__linq__1=11087

and @p__linq__1=11011, 10952, 10835, 10702 for ALFKI.

Note 1: Deleting and recreating Order entities to accommodate changes to Salesperson (EmployeeID) and ShipVia (ShipperID) aren’t acceptable because OrderID is an int identity field.

Sunday, August 03, 2008

Drag-and-Drop Master/Details Windows Forms Still Missing from Entity Framework SP1 Beta

LINQ to SQL Master/Details Form Generated by Dragging Entities and EntitySets

Updated 8/3/2008: “What’s Needed from the EF Team in Addition to Exposing EntityReference<T> and EntityCollection<T> As Data Source Nodes” topic added at end.

LINQ to SQL has supported drag-and-drop generation of master/details and master/details/subdetails forms from the Data Sources window since its first appearance in an early Orcas beta release. Although this approach to rapid application development (RAD) of data-intensive applications is best suited to demos at technical conferences, there are many production and administrative scenarios that can take advantage of Windows application designs similar to Figure 1:

Figure 1. An example of a LINQ to SQL master/details/subdetails Windows application created by dragging-and-dropping from the Data Sources window.

As is evident in the preceding screen capture, LINQ to SQL surfaces foreign key values, such as Order.CustomerID, Order.EmployeeID, and Order.ShipVia (not visible.) The Orders DataGridView has Customer, Employee, and Shipper columns that display type information (Application.EntityType) for many:one EntityRefs, which are hidden from the user but accessible from the BindingSource.Current property value.

Limitations in Entity Framework’s Drag-and-Drop Implementation

The version of Entity Framework (EF) v1 in the Visual Studio 2008 SP1 Beta release can drag-and-drop TextBox or DataGridView icons from the Data Sources window to the form in design mode, but the Data Source nodes don’t include EntityReferences, such as Order.Employee and Order.Shipper, or EntityCollections, such as Customer.Orders or Order.Order_Details. Neither does the current EF v1 release display foreign key values unless they’re part of a primary key, such as Order_Detail.OrderID and Order_Detail.ProductID, as is evident in Figure 2:

Figure 2. An example of an Entity Framework master/details/subdetails Windows application created with the same process as Figure 1. 

Natural keys are primary keys that supply meaningful values to their corresponding entity properties; surrogate keys, such as GUIDs or arbitrary auto-incrementing integers, have no relationship with an entity instance other that its identity and navigation. I requested that EF provide optional visibility of foreign key values as item #9 in my Defining the Direction of LINQ to Entities/EDM post of May 29, 2007 to which EF architect Michael Pizzo replied in a comment:

9. Provide read-only access to foreign key values.

This is actually a feature I’m fighting to get into our final milestone for V1. Can you describe the scenarios where this is used? Do you need the ability to query on the foreign key value, or simply expose it on the domain object?

I described the scenario to Mike as emulating LINQ to SQL’s autogenerated databound grids, which let you change EntityRef foreign key values that aren’t a component of the object’s EntityKey, such as Order.Employee and Order.ShipVia.

EF development lead Danny Simmons said in his reply to a question regarding EF databinding in the ADO.NET Entity Framework and LINQ to Entities (Pre-release) forum’s Re: BrowsableAttribute for certain properties / no properties for foreign keys thread started December 28, 2007:

It is our intention to support this kind of model for asp.net data binding using the entity data source control which should be available by EF v1 RTM.  We don't currently have plans to support this for winforms/wpf data binding in the first release, though.  We'll work on ways to simplify this kind of pattern in future releases.

It appeared at this point that Mike had lost the fight.

Subsequent EF Navigation Property Developments Post-Beta 3

The EF team’s Diego Vega said on May 2, 2008 at the end of Re: DataMember not visible when using BindingSource connected to Entity Framework Beta3 thread:

[T]he reality up to beta 3 was that Entity Framework binding lists would not expose navigation properties for one-to-many or many-to-many relationships for databinding.

In more recent bits, we incorporated several improvements to our databinding story. In the final release of EF v1, you should be able to implement the master-detail scenario you describe without writing any code to synchronize both DataBound controls.

Also, we implemented the necessary interfaces for drill-down capabilities.

In the meanwhile, I can tell you that the mechanism that was used in beta 3 to hide collection navigation properties was based in a [Browsable(false)] attribute we placed in those properties in the code-gen classes.

Removing that attribute causes the databinding list to start exposing the collection property, but unfortunately this is not a good workaround, since the whole code-gen class is overwritten every time you change your Entity Data Model. [Emphasis added.]

The two points at which navigation properties might have been exposed, “up to beta 3” or after beta 3 (“was used in beta 3”), or after SP1 Beta (“final release of EF v1”). Microsoft released VS 2003 SP1 Beta on May 12, 2008.

However, it turns out that data binding didn’t get fixed in SP1. Diego Vega says in his Re: Databinding on navigation Properties post of July 25, 2008:

After SP1 beta we improved a lot of things around databinding. Among them, we removed the Browsable(false) attribute from navigation properties, and we got teams in Visual Studio and WinForms to change things a little bit so that databinding to nested EntityCollection<T> actually works both in design-time and runtime.

As a result, in a WinForms application in recent builds, you can just drag and drop Customers and Customers.Orders from the Data Sources window, then write a couple of lines of code that look like this (from the top of my mind, sorry if it does not compile):

protected NorthwindEntities contex = new NorthwindEntities()
protected void Form_Load(object sender, EventArgs e)
{
    bindingSource.DataSource = context.Customers.Include(Orders);
}
And you get a very simple master-detail scenario running. [Emphasis added.]

I haven’t heard anything about a VS 2008 SP1 Beta 2 or RC1, so it appears to me that EF v1 data binding for WinForms will arrive at RTM with no external testing.

What’s Needed from the EF Team in Addition to Exposing EntityReference<T> and EntityCollection<T> As Data Source Nodes

Hopefully, the testers will put EF databinding through the paces with multi-level DataGridView controls with bound ComboBox cells such as that shown in Figure 3. I’m finding some strange behavior with LINQ to SQL and ComboBoxColumns that doesn’t occur with DataSets as the data source.

Figure 3: The form of Figure 1 with data-bound ComboBoxColumns added and unnecessary CustomerID column removed from the detail DataGridView.

Fulfilling Diego’s promise that developers using Entity Framework v1 “can just drag and drop Customers and Customers.Orders from the Data Sources window, then write a couple of lines of code” that enable nested EntityCollection<T> associations to populate detail grids isn’t enough. We’ll also need sample code at RTM to:

  1. Display scalar primary key property values from EntityReference<T> associations (such as Order.Customer.CustomerID, Order.Employee.EmployeeID, and Order.Shipper.ShipperID) as editable TextBoxColumn values to emulate LINQ to SQL’s default foreign key value.
  2. Display meaningful scalar property values from EntityReference<T> associations (such as Order.Customer.CompanyName, Order.Employee.LastName, and Order.Shipper.CompanyName) as read-only TextBoxColumn values to emulate tje default Order grid display of ASP.NET Dynamic Data (DD).
  3. Enable updating EntityReference<T> associations with ComboBoxColumns as shown for the SalesPerson and ShipVia columns of the Order DataGridView (DGV) and ProductName column of the Order_Details DGV to emulate DD’s Edit page for Order entities. Deleting and recreating an entity to update an EntityReference<T> isn’t acceptable for entities, such as Order, which have an autoincrementing primary key. 
  4. Display read-only foreign key values in unbound cells without requiring user action (such as clicking in the cell), as shown for the Order_Details DGV’s SKU column.
  5. Update bound entity property values when changing a related value, such as replacing the Order_Details DGV’s UnitPrice value when changing a Product association.

If EF v2’s POCO entities can’t build in the preceding features or provide them in a VS 2008 add-in, CTP and beta drops should provide the preceding sample code elements for testers.

If EF v1 can’t accomplish the preceding five tasks with added code, in the spirit of “transparent development” the EF team should advise potential EF users of specific limitations as soon as possible.

Dell Attempts to Purloin “Cloud Computing” Trademark

Updated 8/18/2008: Sam Johnston reports in his “Dell Denied: 'Cloud Computing' both desciptive and generic” post of of 8/15/2008 that the US Patent and Trademark Office (USPTO) have denied Dell, Inc.’s application for a trademark (actually a servicemark) on “Cloud Computing.”

Updated 8/3/2008: See “Subsequent Events”

Dell Inc. isn’t short on chutzpa. The Round Rock computer maker has redefined the term “Cloud Computing” to cover:

Design of computer hardware for use in data centers and mega-scale computing environments for others; customization of computer hardware for use in data centers and mega-scale computing environments for others; design and development of networks for use in data centers and mega-scale computing environments for others; Consulting services for data centers and mega-scale computing environments in the fields of design, selection, implementation, customization and use of computer hardware and software systems for others; Consulting services for data centers and mega-scale computing environments in the fields of design, selection, implementation, customization and use of computer hardware and software systems for others.

and is attempting to register a trademark (®) for the term. None of the preceding terms conform to the accepted definitions for cloud computing of which I’m aware. Wikipedia’s entry is closest to the mark for me.

If there’s one computer company I don’t associate with cloud computing or any other form of new or high technology, it’s Dell. Dell is famous primarily for its poor customer service and miserly research and development budgets.

The story and a link to Dell’s application to the U.S. Patent and Trademark Office (USPTO) is in the Washington Post’s “Dell Tries to Trademark 'Cloud Computing” article of August 2, 2008.

I’m not an attorney, but I’ve applied for and obtained registered trademarks for products in long-past avatars. I also obtained a sever-figure settlement from a former business parter for, in part, infringing my Helix® registered trademark for liquid flowmeters.

It was my understanding that you must declare a first use (in commerce) date on the registration papers to obtain a registered trademark (®). The first requirement might have changed, because the application’s First Use and First Use in Commerce dates show “DATE NOT AVAILABLE.” However, the application appears to be of the “Intent to Use” type, which requires filing an “Allegation of Use” within six months.

If I had seen the Notice of Publication in time, I would have filed an opposition.

Subsequent Events

Cyndy Aleo-Carreira’s “Dell tries to trademark ‘cloud computing’” article of August 1, 2008 on the The Industry Standard site has the following comment by Owen Smigelski:

I'm a trademark attorney, and Dell has done more than just "try" to use the trademark. The application was published for opposition, no one lodged any complaints, and now the trademark will proceed to registration (once Dell submits examples of its trademark use). The mark can later be disputed once it is registered by anyone who believes they will be harmed by the registration of the trademark by Dell. Examining Attorneys at the USPTO usually catch phrases that are generally used by the public, thus I am surprised they let this one through with approval.

Here's a direct link to check the status of the application: http://tarr.uspto.gov/servlet/tarr?regser=serial&entry=77139082

Dell is already using the common-law trademark symbol (™) in conjunction with “cloud computing.” Cyndy links to a message from Sam Johnson in the Cloud Computing Google Group. The writer had “spotted something curious - a trademark (™) symbol associated with 'Cloud Computing' in a Dell press release”:

Dell today announced the availability of the Dell Cloud ComputingTM  Solution, the first offering developed by its new business unit – the Dell Data Center Solutions Division.

There are no “goods” included in Dell’s Class Status list, only “services.” Therefore, it seems to me that Dell should have applied a common-law servicemark (℠) symbol rather than a trademark (™). But (according to Wikipedia, these common-law servicemarks and trademarks have no legal standing. The HTML entity for a servicemark is &#x2120; or &#8480;, which appears as ℠.

Saturday, August 02, 2008

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

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

Updated 8/3/2008: Additions and updates

Steve Naughton Demos Use of the ADO.NET Dynamic Data Futures’ AutoComplete and CascadingFilter FieldTemplates

Windows client UIs commonly apply an AutoComplete feature that fill lists with partial-matching combo box selections while you type. But this feature appears less commonly in Web forms. Steve’s Dynamic Data and Field Templates - An Advanced FieldTemplate of August 2, 2008 describes how to combine the AutoCompleteFilter.asmx, AutoCompleteStyle.css, and AutoComplete.ascx files from the ADO.NET Dynamic Data Futures Project download on CodePlex to create an AutoCompleteText_Edit FieldTemplate.

If your WebForms’ combo box lists grow to exceed your page height, you probably need to group selections by category, which requires what the ADO.NET Dynamic Data team calls a CascadingFilter. The CascadingFilter FieldTemplate also is part of the ADO.NET Dynamic Data Futures Project download from CodePlex.

Steve’s Dynamic Data and Field Templates - A Second Advanced FieldTemplate second post of August 2 shows you how to use the CascadingFilter field template to group a Product combo box by Category using the Northwind sample database and LINQ to SQL data sources.

Added: 8/3/2008

Michael Neel Uses LINQ to XML to Generate XHTML

His Using LINQ to generate HTML post of August 3, 2008 shows how to use LINQ to XML expression syntax and the XElement type to generate XHTML to populate agenda pages for the CodeStock Website.

Added: 8/3/2008

Eric White Uses LINQ to XML to Minimize Lines and Speed-Read Code

Eric’s LINQ Reduces Line Counts and Makes Code “Pop” post of August 2, 2008 demonstrates how to move from traditional imperative-style coding to a functional approach with LINQ to XML. A simple example shortens a 22-line foreach method to 12 lines of much easier-to-read method that uses chained LINQ to XML method-call syntax.

Added: 8/3/2008

Michael Neel Uses LINQ to XML to Generate HTML

His Using LINQ to generate HTML post of August 3, 2008

Dell Attempts to Purloin “Cloud Computing” Trademark

Dell Inc. isn’t short on chutzpa. The Round Rock computer maker has redefined the term “Cloud Computing” and is attempting to obtain a trademark on it for a wide range of computer-related services, none of which conform to the accepted definitions for cloud computing of which I’m aware. Wikipedia’s entry is closest to the mark for me.

For more details, see my Dell Attempts to Purloin “Cloud Computing” Trademark post of August 2, 2008.

Updated: 8/3/2008

Drag-and-Drop Master/Details Windows Forms Still Missing from Entity Framework SP1 Beta

LINQ to SQL has supported drag-and-drop generation of master/details and master/details/subdetails forms from the Data Sources window since its first appearance in an early Orcas beta release.

The version of Entity Framework (EF) v1 in the Visual Studio 2008 SP1 Beta release can drag-and-drop TextBox or DataGridView icons from the Data Sources window to the form in design mode, but the Data Source nodes don’t include EntityReferences, such as Order.Employee and Order.Shipper, or EntityCollections, such as Customer.Orders or Order.Order_Details. Neither does the current EF v1 release display foreign key values unless they’re part of a primary key, such as Order_Detail.OrderID and Order_Detail.ProductID.

Read more about the problem at Drag-and-Drop Master/Details Windows Forms Still Missing from Entity Framework SP1 Beta of August 2, 2008.

Updated: 8/3/2008

Andrew Matthews Seeks Community Help with Enhancing LINQ to RDF

Andrew’s Wanted: Volunteers for .NET semantic web framework project post of August 2, 2008 observes:

LinqToRdf* is a full-featured LINQ query provider for .NET written in C#. It provides developers with an intuitive way to make queries on semantic web databases. The project has been going for over a year and it’s starting to be noticed by semantic web early adopters and semantic web product vendors. LINQ provides a standardised query language and a platform enabling any developer to understand systems using semantic web technologies via LinqToRdf. It will help those who don’t have the time to ascend the semantic web learning curve to become productive quickly.

He’s seeking help for development, testing, and promotion, as well as several new features:

  • Reverse engineering tool
  • Tutorials and documentation
  • Supporting SQL Server
  • Porting to Mono
  • SPARQL Update (SPARQUL) support
  • Demonstrators using large scale web endpoints

Eugenio Pace Explains SQL Server Data Services’ Entity Versioning and Concurrency Conflict Management

SOAP requests to SSDS entities require a Scope with an instance of the new (in Sprint 3) VersionMatch class to manage concurrency conflicts. Eugenio’s Concurrency in SSDS post of August 1, 2008 shows you how to implement and test it.

Chad Myers Proposes Expression-Tree Query Objects for Use by Repositories

Chad concludes that the single repository model has …

the potential for business logic (also known as ‘where’ clauses) to creep into the repository which would be bad. Perhaps a better alternative would be to encapsulate the specific logic of a given query into an object. You could then have this object produce something that the repository could (blindly, decoupled) use to query on.

This approach allows you to maintain the one repository approach, yet still have encapsulated domain-specific queries. Plus, you can test your queries independently of the repository which is a huge benefit.

He then goes on to demonstrate using an expression tree to create the query object in Query Objects with the Repository Pattern (Part 1) of August 1, 2008 and enhances the objects by coupling then with AndAlso and OrElse expressions in Query Objects with the Repository Pattern (Part 2) of August 2, which provides a full query object implementation.

Comment: Ayende Rahien contends that Chad’s syntax “leaves a lot to be desired” in his Unreadable Linq post of August 2, 2008.

Mehfuz Releases LINQ to Flickr 1.4 with New Features

Mehfuz’ Athena - A LINQ to flickr API (Release 1.4) post of August 2, 2008 says:

I have updated it with the latest LINQExtender (pre release version)  containing updated Object Tracking Service (OTS) that will enable it to update photos and comments as if like LINQ to SQL.

It also adds Extras support, which enables querying with Extras enum for additional information about your photos.

Article about ADO.NET Data Services by the Flaskos in August 2008 MSDN Magazine

Elisa and Mike Flasko’s “Expose And Consume Data in A Web Services World” article appears in the August 2008 issue of MSDN Magazine. In addition to demonstrating the usual Entity Framework back-end, the article shows you how to create an Astoria service for an in-memory CLR objects.

Note: Julie Lerman wrote Write On!: Create Web Apps You Can Draw On with Silverlight 2 for this issue. Read more about it in her Drawing in Silverlight Article in MSDN Magazine of July 2, 2008.

Input Needed for Alternative Approaches to Implementing POCO in Entity Framework v2

Alex James is is seeking the answers to the following three questions for enabling Plain Old CLR Objects (POCO) in EF v2:

  1. What are the interesting scenarios for using the state management API in POCO scenarios?
  2. What API pattern is better? Having an explicit method to compute the current state based on the snapshot comparisons or having the state to be computed automatically when accessing the state?
  3. Is it better to have an Invalid state for entries or should the state manager just throw exceptions immediately every time it finds a change on a key?

His Discussion about API changes necessary for POCO post of August 1, 2008 offers a extensive discussion of the implications of alternatives for questions #2 and #3.

Favorable Competitive Side-Effects from the Entity Framework v1 Release Anticipated

Gary Short of Developer Express concludes that XPO Will Benefit from the Entity Framework (August 1, 2008) because:

[M]any companies and many individual developers too for that matter, will not contemplate looking at a new architectural paradigm until such time as it appears on the Microsoft development stack. …

With the release of Visual Studio 2008 SP1 this summer, that is all about to change, an ORM tool (albeit a flawed one) will then become a first class citizen in the Microsoft development stack. That fact will open up the world of ORM to many more people, and as those people explore that new world many will drift to XPO and other ORM tools, making 2009, in my opinion, a great year to be in the ORM space.

Mike Amundsen Posts Code and Demo for Twitter-Like SSDS Application

Mike’s Online Guestbook Demo App up and running post in the of July 31, 2008 in the SQL Server Data Services (SSDS) - Getting Started forum announces the availability of source code for his SSDS Online Guestbook application that logs 140-character messages similar to Twitter Tweets.

Mike describes his project:

This app uses a single Container (guestbook) with two Entity 'Kinds' (guest and message). Users can create an account and then post messages for everyone to see. You can also filter the message list by guest's nickname. 

I'm testing out the user account authentication pattern (a custom HTTP Basic using cookies for browsers) and the notion of running queries in a single container over multiple 'Kinds.'  I am also working on a solid list/query caching (and cache _invalidation_) pattern as SSDS does not yet support ETags/caching of lists.

He also has a live demo of the application running on his site.

Mary Jo Foley Describes SCOPE, Microsoft’s SQL-Like Answer to MapReduce for Parallel Queries Against Massive Data Sets

Mary Jo describes Microsoft Research’s Structured Computations Optimized for Parallel Execution (SCOPE) in her Microsoft’s road to the cloud is paved with parallelism post of July 31, 2008. The “SCOPE: Easy and Efficient Parallel Processing of Massive Data Sets” whitepaper is the basis of a Microsoft presentation at the Very Large Data Bases 2008 conference scheduled for August 23 – 28, 2008 in Auckland, New Zealand.

Mary Jo quotes Greg Linden, a former Amazon developer who founded Findory.com and now works in Microsoft’s Live Labs group:

Scope is similar to Yahoo's Pig, which is a higher level language on top of Hadoop, or Google's Sawzall, which is a higher level language on top of MapReduce. But, where Pig focuses on and advocates a more imperative programming style, Scope looks much more like SQL.

Gregg concludes his post:

Please see also my past posts on related work, including "Yahoo, Hadoop, and Pig Latin", "Sample programs in DryadLINQ", "Automatic optimization on large Hadoop clusters", and "Yahoo Pig and Google Sawzall".

The white paper notes that:

“Microsoft has developed a distributed computing platform, called Cosmos, for storing and analyzing massive data sets. Cosmos is designed to run on large clusters consisting of thousands of commodity servers. Disk storage is distributed with each server having one or more direct-attached disks.”

Mary Jo mentioned Cosmos in her Windows Live Platform Services: A guide for the perplexed post of March 6, 2008.

I don’t believe that SCOPE or Cosmos have a direct relationship to SQL Server Data Services (SSDS) today. However, one of the reasons that SSDS initial design is schemaless, implements flexible entities, and has little resemblance to traditional relational database management systems (RDBMSs) might be compatibility with a future SSDS upgrade or different version that runs under SCOPE and uses the Cosmos file system.

Comment: Ayende Rahien has a lot to say on the topic in his Thinking about Cloud Computing post of August 2, 2008.

Bart De Smet Updates LINQ to ActiveDirectory

Bart’s LINQ to AD - Refresh Release 1.0.1 Available post of July 31, 2008 announces an update to LINQ to AD (formerly LINQ to LDAP) that adds the following features:

  • byte[]- and GUID-valued directory attributes
  • Bug fix for non-constant EndsWith, BeginsWith and Contains clauses
  • Introduction of DirectoryContext with support for nested contexts and direct update support
  • Updated samples to use the new available features

Mike Taulty on Calling ASMX Web Services from Silverlight 2 Clients

Mike’s Silverlight 2 Beta 2 - ASMX Services & XmlSerializer post of July 31, 2008 verifies that you can call ASMX services from Silverlight 2 Beta 2 when those services use the XmlSerializer instead of the DataContractSerializer.

Steve Naughton Discovers a Fifth ASP.NET Dynamic Data Custom Page Type

ASP.NET Dynamic Data maven Steve Naughton finds a fifth custom Page type and demonstrates how to code for the user’s current culture in his Dynamic Data Custom Pages Part 5: I18N? Internationalisation Custom Page post of July 31, 2008.

Rob Conery Replaces LINQ to SQL’s Traditional Lazy Loading with LazyList

Rob and Ayende Rahien come up with a new approach to Lazy Loading With The LazyList implementation of IList<T> that takes an IQueryable definition in its constructor. This July 30, 2008 post shows you how to include LINQ Let statements …

This is part of fooling Linq To Sql so it doesn't try to introspect this relationship and build some weird SQL statement. I had to create these methods and they are simply filter statements that return IQueryable<Product> (you can see these in the checked in Storefront code).

Rob concludes with the source code to implement LazyList<T>.

Ben Hoelting Questions the Future of ADO.NET DataSets After Microsoft Releases the Entity Framework

Ben stated "if you are creating new applications or just adding on features to your current app I would use LINQ or EF instead of ADO Datasets” and an earlier post and goes on to detail the reasons in his Are ADO.NET Datasets dead? post of July 30, 2008.

I don’t believe that DataSets are dead, but they’ll certainly be on life support in a year or two.

Data Platform Group Posts ADO.NET Data Services and Entity Framework Screencasts

Its “How Do I?” Videos — Data Platform Development page offers links to two recently added “How Do I” ADO.NET Data Services (Astoria) screencasts:

and the following screencasts for Entity Framework: