views:

84

answers:

2

My application is a client/server solution using an ADO.NET Data Service. The Data Service exposes transactionSummaryData as follows:

public IQueryable<TransactionSummary> TransactionSummaries
{
    get { return MainForm.transactionSummaryData.Items.AsQueryable(); }
}

The transactionSummaryData is of type TransactionSummaries whose items property is defined as follows:

public List<TransactionSummary> Items

On the client side, I have some controls databound to a LINQ query which works on the TransactionSummaries:

AvailibilityBox.DataContext = (from salesdata in srv.TransactionSummaries
                               where salesdata.PerformanceID == selectedshow.performancedata.PerformanceID
                               select salesdata);

This gets executed many times as selectedshow.performancedata.PerformanceID changes in response to the user navigating the UI.

All good so far. However, when the transactionSummaryData on the server is updated by some other code within the server, the client continues to display 'stale' data and doesn't notice the update. I assume this is due to some kind of caching. Having debugged the code, I can see the server sending the right data but the LINQ query on the client continues to return the stale data. Restarting the client causes the correct data to be displayed.

I think i'm missing something obvious here, but I can't see how to control any caching on the client or invalidate the object without re-making the connection.

A: 

If you set your DataContext's "ObjectTrackingEnabled" property to false, your problem should hopefully go away. See the MSDN link here:

http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.objecttrackingenabled.aspx

womp
I can't find the "ObjectTrackingEnabled" property on the DataServiceContext i'm using (not DataContext).
Ian Gregory
Oops... completely misread the first two sentences.
womp
+1  A: 

Hi, Emre Meric on the Microsoft forums managed to answer my question:

The default merge option for DataServiceContext is AppendOnly, meaning that if an entity returned by a query is already being tracked by the context, no changes will be made to it. You can set the MergeOption to OverwriteChanges if you want the entity to be updated from the persisted storage at all times.

MSDN Reference

Ian Gregory