0

時得到填充到Silverlight 4中的GridView我目前遇到的問題是如下:「重複」數據使用NHibernate,LINQ到NHibernate和Castle.Windsor

我在Silverlight 4的應用程序,它有一個GridView獲取數據填充。但是,數據是從數據庫中取回並在網格視圖中重複x次的對象集合中的第一個條目。

當我在DAL和域服務上放置一個斷點時,被帶回的數據是正確的,即它返回集合中的所有不同對象。

如果我將數據綁定到非Silverlight組件,這不是一個表現出來的問題。

現在對於一些代碼,這裏是我如何在Silverlight應用程序綁定數據:

private void BindData() 
    { 
     _ctx = new ManufacturingDomainContext(); 

     _loadOp = _ctx.Load(_ctx.GetWorkCellLoadGraphDataByIdQuery("Test", DateTime.Today, DateTime.Today.AddDays(14)), TestCallBack, null); 
    } 

    private void TestCallBack(LoadOperation<WorkCellLoadGraphData> obj) 
    { 
     CustomerGrid.ItemsSource = _loadOp.Entities; 
    } 

域名服務代碼是:

public IEnumerable<WorkCellLoadGraphData> GetWorkCellLoadGraphDataById(string workCellId, DateTime startDate, DateTime endDate) 
    { 
     WorkCellLoadGraphData data = new WorkCellLoadGraphData(); 

     var result = ManufacturingDao.Instance.GetWorkCellLoadGraphDataByIdA(workCellId, startDate, endDate); 


     return result; 
    } 

最後的DAL代碼是:

public IList GetWorkCellLoadGraphDataByIdA(string workCellId,DateTime startDate,DateTime endDate) { IList結果= new List();

 using (var session = this.GetSession()) 
     { 

      var criteria = session.CreateCriteria(typeof(WorkCellLoadGraphData)); 

      criteria.SetProjection(
       Projections.ProjectionList() 
        .Add(Projections.Property(WorkCellLoadGraphData.WorkCellIdPropertyName), "WorkCellId") 

        .Add(Projections.Property(WorkCellLoadGraphData.FromTimePropertyName), "FromTime") 
        .Add(Projections.Property(WorkCellLoadGraphData.DurationPropertyName), "DurationInMinutes") 

       ); 

      criteria.Add(Restrictions.InsensitiveLike(WorkCellLoadGraphData.WorkCellIdPropertyName, workCellId)); 
      criteria.Add(Restrictions.Between(WorkCellLoadGraphData.FromTimePropertyName, startDate, endDate)); 

      criteria.SetResultTransformer(new AliasToBeanResultTransformer(typeof(WorkCellLoadGraphData))); 

      results = criteria.List<WorkCellLoadGraphData>(); 
     } 

     foreach (var x in results) 
      Logger.Info(x.ToString()); 

     return results; 
    } 

作爲主題中提到的所有技術的初學者,我不確定哪個區域可能是問題所在。我嘗試過放置斷點,但使用異步調用,事情並不容易遵循。

此外,我必須補充說,通常我會從我的POCO類調用DAL代碼,而不是完全繞過POCO。

誰能幫助?

大衛

回答

0

好這個問題苦苦掙扎的同時,我們發現了什麼問題了。實際上,在返回我們的對象的集合看起來是這樣的:

  • 「someID」,今天,1
  • 「someID」,明天,1
  • 「someID」,NextMonth,1

等等。

問題在於「someID」,因爲我相信Silverlight期待着一些獨特的東西。所以,如果相反,我們傳遞的數據出來作爲

  • 「someID」,今天,1
  • 「someID1」,明天,1
  • 「someID2」,NextMonth,1

的「正確的「數據將被返回。

我真的希望這可以幫助別人,因爲我們浪費了很多時間。