WCF RIA 查询缓存
sl5+wcf ria +ef
在sqlserver手动修改了数据库的数据以后,再到前台去刷新数据,发现数据没有变化,服务端返回和前台不一致
服务端代码
public IQueryable<Customer> GetCustomerByCustomerId(string customerId)
{
return this.ObjectContext.Customer.Where(e => e.CustomId == customerId);
}
客户端更新按钮代码
private void Button_Click(object sender, RoutedEventArgs e)
{
customerContext.Load<Customer>(customerContext.GetCoustomerByCustomerIdQuery("000001")).Completed += (s, x) =>
{
customer = (Customer)((LoadOperation<Customer>)s).Entities.FirstOrDefault();
MessageBox.Show(customer.CustomName + customer.Address);
};
}
例如修改了编号000001的customerName和customerAddress
在后台查看返回数据

前台获取的数据

原本以为是EF的查询缓存造成这个现象,但是服务端的结果显示 EF已经把最新的结果返回,于是搜了一下关于WCF RIA的查询缓存,找到了答案
RIA在客户端内存中存有EntitySet的缓存,使用LoadBehavior.RefreshCurrent ,刷新缓存
customerContext.Load<Customer>(result,LoadBehavior.RefreshCurrent,true).Completed += GetCustomerComplete;
参考地址 http://blog.csdn.net/jameszhou/article/details/5841242
http://weblogs.asp.net/fredriknormen/refresh-the-cached-entityset-after-a-submitchanges-wcf-ria-services
浙公网安备 33010602011771号