locked
Data service caching issue RRS feed

  • Question

  • Hi

    In my VS solution,  I have two projects, one is a Silverlight5 app and the other is a WCF Services app. My Silverlight5 app is hosted on a page in the WCF Services app. In the service app, I added a ADO.NET Entity Data Model, and a WCF data service that maps to this data model. I reference the data service in my Silverlight5 app. This works and I can also query and update my database from the Silverlight5 app using the data service.

    The problem that I have is in the Silverlight5 app. For example I have a UserControl called Customers which allows users to add/edit/delete customer records and another called OrdersReports which allows users to select a Customer record from a drop down and then list the orders for that particular customer in a DataGrid below. If the count of orders is zero, it displays "No order to display". In the background of the two user controls, I instantiate a variable _dataService which creates an instance of the data service reference allowing me to communicate with the data service. The user clicks the option to edit customers and loads the Customers UserControl. Data service is instantiated and the user can add, edit and delete records as intended. For example, if the user adds or edits a customer record at that point, everything is saved in the database perfectly. When the user clicks the option for the OrdersReport UserControl, this loads and the data service client is intantiated. The code loads a Customer data service collection with all customer data (to display in drop down) and expands on the Orders node to also bring in the list of orders per customer (to display in data grid). In this case, customers without orders are also retrieved and their Orders property is a empty collection. My problem is that if the user had just added or edited a customer record in the Customers UserControl and even saved these changes, when the OrdersReport UserControl loads, the new or edited customer record is not listed. If I close the app and reopen, then the new and changes are listed.

    I would like to find out what is causing this and what is the best method to solve it. Someone has recommended that I instantiate my data service client at the application level and then use it for data service operations everywhere in my app. For sure that works, but this is not efficient because I do not need data service operations everywhere in my app and to leave that object there instantiated when I do not need it is against every rule of good and efficient programming. I think that I am dealing with a cache issue here because the Customers do get saved to the database, but data service calls in OrdersReport seem to be retrieving its data from a cache somewhere. How do I get it to read from the database all the time?

    Regards

    Terence
    Tuesday, June 4, 2013 9:42 AM

All replies

  • Hi Terence,

    Can you tell if the request reaches the data service or if it's cached before that?

    You can figure that with an application like Fiddler. That should tell you if the request reaches the server and what was the exact answer the server sent.

    Best regards,

    Fernando Rocha

    Wednesday, June 12, 2013 1:41 AM