2010-08-09 71 views
1

我有一个数据类,从一个WCF DataService的返回某个对象的Silverlight应用程序被retrurning duplcate行:WCF数据服务查询,似乎在重复的查询

无效ExecuteWipReportQuery(化DataServiceQuery QRY) { 上下文=新StaffKpiServices.HwfStaffKpiEntities(theServiceRoot); qry.BeginExecute(新的AsyncCallback(A => { 尝试 { IEnumerable的结果= qry.EndExecute(一); OnDataLoadingComplete(新WipReportByMonthEventArgs(结果));} 捕获 (异常前) { OnDataLoadingError (ex); } }),null); }

然后视图模型获得这样的结果,并将它们添加到一个观察到的集合:

空隙wipReportDataContainer_DataLoadingComplete(对象发件人,Domain.WipReportByMonthEventArgs E) { Application.Current.RootVisual.Dispatcher.BeginInvoke(( )=> { this.wipReport.Clear(); 字符串s = “”;

  foreach (StaffKpiServices.WipReportByMonth r in e.Results) 
      { 
       //this.wipReport.Add(r); 
       //s += r.ClientCode; 
       this.wipReport.Add(new StaffKpiServices.WipReportByMonth 
       { 
        ClientCode = r.ClientCode, 
        ClientGroup = r.ClientGroup, 
        ClientName = r.ClientName, 
        ClientType = r.ClientType, 
        FinancialYear = r.FinancialYear, 
        Month = r.Month, 
        OSDebt = r.OSDebt, 
        OSDisb = r.OSDisb, 
        OSOther = r.OSOther, 
        OSTime = r.OSTime, 
        OSTotal = r.OSTotal, 
        PartnerUserName = r.PartnerUserName, 
        PracName = r.PracName, 
        Recov = r.Recov, 
        RecovFees = r.RecovFees, 
        RecPerc = r.RecPerc, 
        SicCode = r.SicCode, 
        SicParentName = r.SicParentName, 
        StaffName = r.StaffName, 
        YTDFees = r.YTDFees, 
        YTDTime = r.YTDTime 
       }); 

       s += r.ClientCode + " "; 

      } 
      string s2 = ""; 
      foreach (var p in this.wipReport) 
      { 
       s2 += p.ClientCode + " "; 
      } 
      OnPropertyChanged("WipReport"); 
      if (null != LoadComplete) 
      { 
       LoadComplete(this, EventArgs.Empty); 

      } 
     }); 
    } 

一切正常确定,但如果该数据是refres hed两到三次,那么集合retrun包含正确数量的对象,但都具有重复的属性。似乎没有任何理由,这就好像这个foreach没有在集合上工作,但同时又没有返回任何错误。有任何想法吗?

回答

1

好,所以这很奇怪..但通过重新创建提取数据的对象(创建上下文的数据),一切正常,但如果viewmodel保持活动负责运行数据服务查询的对象,则问题发生.....

我不知道为什么这应该是,但问题已消失.....