home · blog · groups · about us · contact us
DevelopmentNow Blog
 Thursday, March 27, 2008
 
 

FYI, there's a bug in the RTM LinqDataSource where child tables aren't loaded unless you have updating or deleting enabled. Apparently if you have a LinqDataSource that doesn't have updates or deleted enabled, ObjectTracking is turned off (for performance reason), but deferred queries (e.g. queries to pull back child rows) aren't executed.

So statements like

<%# Eval("ChildTable.ChildTableField") %>

in your ListView, etc. won't work.

Annoying, needless to say. But at least now I know.

So, there are a few options:

  1. Set EnableUpdate="true", which will enable ObjectTracking and cause deferred updates to work
  2. Add a SELECT statement in your LinqDataSource (e.g. SELECT="new (field1, field2, childTable)") to pull back everything you need.
  3. Handle the ContextCreated event to either manually set ObjectTrackingEnabled, or manually set LoadOptions.
public void OnContextCreated(object sender, LinqDataSourceContextEventArgs e) {
  ((DataContext)e.ObjectInstance).ObjectTrackingEnabled = true;
} 

OR 

public void OnContextCreated(object sender, LinqDataSourceContextEventArgs e) {
    var dataLoadOptions = new DataLoadOptions();
    dataLoadOptions.LoadWith<MyTable>(t => t.ChildTable);
    ((DataContext)e.ObjectInstance).LoadOptions = dataLoadOptions;
}

Setting LoadOptions is normally the best approach for performance.

March 27, 2008    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]

Related posts:
Linq to SQL: Cast Stored Procedure Results to Table Entities
Grouping in Linq to SQL vs SQL
Some .NET blogging engines
SubSonic DAL layers in Visual Studio
ASP.NET or LAMP for Web Development?
HTTP Compression for ASP.NET Sites


« March Portland Open Coffee Club | Main | Grouping in Linq to SQL vs SQL »