请教Linq查询不更新的问题
通过DomainService,在Silverlight中对表进行查询,其中有一个要求刷新实时表的实时数据的要求。
即每隔一定的时间,查找实时表,并将实时数据读取出来。
问题:
- C# code
private void LoadRealTimeData() { var query = from r in this.dmdc.GetRealTimeQuery() where r.VarID == 30 select r; this.RealTimeEntities = this.dmdc.Load<RealTime>(query); this.RealTimeEntities.Completed += new EventHandler(RealTimeEntities_Completed); } void RealTimeEntities_Completed(object sender, EventArgs e) { List<RealTime> tempList = this.RealTimeEntities.Entities.ToList(); if (tempList == null || tempList.Count < 1) return; RealTime rt = tempList[0]; ///...其它代码 }根据以上代码,通过DispatcherTimer变量,每隔10秒中刷新一次数据,即执行一次LoadRealTimeData(),但是每次读取出的数据都是一样的,即每次项目启动调试的时候会从RealTime表读出数据,但以后的每次执行LoadRealTimeData(),都是的启动时的数据,但是RealTime表中的数据是一直更新的。
求帮助!
[解决办法]
public static Entities myEntities = new Entities();
myEntities.Refresh(RefreshMode.StoreWins, myEntities.Measurements);