Tuesday, May 16, 2006

Workarounds for May 2006 CTP DLinq Problems

While I was writing the sample code that illustrates how to bind DataGridView controls to DLinq Data Sources for my FTPOnline "LINQ Takes Shape in May CTP" article, I encountered these three significant issues: • A True value for the IsID property (id:=true DLinq.Column attribute) is required for each DLinkProperty element of a DLinq Class that's mapped from a primary key field of a relational table having a composite primary key. An instruction in the DLinq Designer.doc file for adding the DLinq Class for the Order Details table (step 7 on page 9) states "Set the IsID property to True (for the OrderID column only)." If you don't set the ProductID field's IsID property value to True also, as shown here, the bound OrderDetailsDataGridView displays erroneous (repeated) values in all rows, as shown here.

Note: Microsoft's Antoine Cote posted the following message on May 18, 2006 in the "Associations in DLinq Designer" thread: "[F]or the CTP, the designer only support[s] single column keys. We're working on supporting composite keys for the next release."

• Deleting rows from bound DataGridView controls manually doesn't persist the deletions to the source tables when you apply the DataContext.SubmitChanges() method. • Code to work around the failure to persist deleted rows throws untrapped NullReferenceExceptions when it encounters the the auto-generated DLinq Designer code's instruction that's emphasized below in the Public Property Customer() As Customer procedure:

If (Not (Me._Customer.Entity) Is Nothing) Then
   'Fix for deletions
   'Me._Customer.Entity = Nothing (moved below)
   Me._Customer.Entity.Orders.Remove(Me)
   Me._Customer.Entity = Nothing
End If
and in the Public Property Order_() As Order_ procedure:
If (Not (Me._Order_.Entity) Is Nothing) Then
   'Fix for deletions
   'Me._Order_.Entity = Nothing (moved below)
   Me._Order_.Entity.Order_Details.Remove(Me)
   Me._Order_.Entity = Nothing
End If
The preceding procedures are auto-generated by the DLinq Designer tool, so it's likely that you'll need to make the changes multiple times. Note: Terry Adams (tadam)—the development lead on the DLinq team—confirms some of these issues in a comment to this post. The article and its sample code, which you download from the "Get the code" link in the Article Tools box on page 1, includes these fixes in the DLinqDataBinding.sln project. This project also demonstrates how to take advantage of the new Optimistic Concurrency Confict Resolution (OCCR) features of the May 2006 CTP of the DLinq bits. Technorati Tags: , , , , ,

0 comments: