问题
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?
回答1:
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'.
回答2:
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
来源:https://stackoverflow.com/questions/7953553/disable-caching-of-domaincontext-domaindatasource-in-silverlight-ria-services