2012-09-11 48 views
0

我試圖讓DomainCollectionView,但總數不包括查詢工作:包括總計數不RIA

public DomainCollectionView<sys_log> collView 
    { 
     get { return (DomainCollectionView<sys_log>)this.GetValue(collViewProperty); } 
     set 
     { 
      this.SetValue(collViewProperty, value); 
     } 
    } 

    public static DependencyProperty collViewProperty = DependencyProperty.Register(
     "collView", typeof(DomainCollectionView<sys_log>), typeof(Journal), new PropertyMetadata(null)); 

    this._source = this.maindatacontext.sys_logs; 
    this._loader = new DomainCollectionViewLoader<sys_log>(this.LoadEntities, this.mdcloaded); 
    this._view = new DomainCollectionView<sys_log>(this._loader, this._source); 

    private LoadOperation<sys_log> LoadEntities() 
    { 
     EntityQuery<sys_log> temp = mdc.GetSys_logQuery().OrderBy(order => order.Id).Where(c => c.date > DateFrom.SelectedDate.Value && c.date < DateTo.SelectedDate.Value.AddDays(1).AddTicks(-1)).SortAndPageBy(this._view); 
     temp.IncludeTotalCount = true; 
     return mdc.Load(temp); 
    } 


    void mdcloaded(LoadOperation<Web.sys_log> t) 
    { 
      this.collView = _view; 
      //but this _view.TotalItemCount = -1 
      dataGrid1.UpdateLayout(); 
    } 

DataGrid1中具有的ItemSource = collView。 如何設置TotalItemCount或將其包含在查詢中?

回答

2

您需要覆蓋DomainService的Count方法以獲取查詢實體的總數。

public class MyDomainService : DomainService{ 
    protected override int Count<T>(IQueryable<T> query) { 
     return query.Count(); 
    } 
} 
0

我認爲它不起作用b'cause你設置查詢相關mdc的IncludeTotalCount。

但是你看看依賴關係類型化的DomainCollectionView < T>。

DomainCollectionView是否由您執行? Silverlight只提供ICollectionView afaik.If你實現DomainCollectionView檢查它。或者只是嘗試使用collView的Count屬性。它可以與ICollectionView的實現相關。上面使用TotalEntityCount的

  var qe=dSrvGD.GetGD_COUNTRYQuery(); 
      qe.IncludeTotalCount = true; 
      dSrvGD.Load(qe).Completed += (s, e) => 
       { 
        if ((s as LoadOperation).TotalEntityCount<=0) 
        { 
         //ASK WHY empty :) 
        } 
       } 
       ; 

說明在這裏,

// 
    // Summary: 
    //  Gets the total server entity count for the query used by this operation. 
    //  Automatic evaluation of the total server entity count requires the property 
    //  System.ServiceModel.DomainServices.Client.EntityQuery.IncludeTotalCount on 
    //  the query for the load operation to be set to true. 

我問過類似的問題 前WCF returned TotalCount -1 but there are Entities, How?

希望幫助