Jim
Jim

Reputation: 21

Disable caching of DomainContext / DomainDataSource in Silverlight RIA Services

I use a DomainDataSource with filter descriptors, but it seems that the DomainDataSource (or DomainContext) is caching old data and not replacing it with fresh data from the database.

<riacontrols:DomainDataSource
        AutoLoad="True"
        LoadSize="5"                        
        Name="employeeDomainDataSource"
        QueryName="GetEmployeeQuery" Width="0" DomainContext="{Binding EmployeeContext}">
        <riacontrols:DomainDataSource.FilterDescriptors>                
            <riacontrols:FilterDescriptor IsCaseSensitive="False" PropertyPath="Name" Operator="Contains" Value="{Binding ElementName=NameFilter, Path=Text}"/>
        </riacontrols:DomainDataSource.FilterDescriptors>
    </riacontrols:DomainDataSource>

I also have a DataPager control.

Suppose user A and B load the data. User B changes the Employee's Name in edit mode. User A types in that new name as filter, the data will be fetched but the old (cached) name is displayed. I used fiddler and I can see that the correct data is returned from the database and the webservice.

Is there any option where I can switch this off?

Upvotes: 2

Views: 2004

Answers (2)

star
star

Reputation: 41

You should set LoadBehavior to RefreshCurrent in you Load method: like this: context.Load(query, LoadBehavior.RefreshCurrent, loadOpt =>{},null);

http://msdn.microsoft.com/en-us/library/system.servicemodel.domainservices.client.loadbehavior%28v=vs.91%29.aspx

Upvotes: 0

TheNextman
TheNextman

Reputation: 12566

I think you need to specify a LoadOption on the data.

I can't remember exactly, and I can't find the documentation, but I believe you need to override the LoadingData event on the DomainDataSource; and set the args.MergeOption. Try 'RefreshCurrent'.

Upvotes: 3

Related Questions