包含总计数在RIA中不起作用

时间:2012-09-11 06:15:49

标签: silverlight datagrid wcf-ria-services collectionview

我尝试获取DomainCollectionView,但总计数不包括在查询中:

    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 个答案:

答案 0 :(得分:2)

您需要覆盖DomainService的Count方法,以获取查询实体的总数。

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

答案 1 :(得分:0)

我认为它不起作用因为你设置了与查询相关的mdc的IncludeTotalCount。

但是你看一下依赖属性类型的DomainCollectionView&lt; T>

您是否实施了DomainCollectionView? Silverlight只提供ICollectionView afaik。如果你实现了DomainCollectionView检查它。或者只是尝试使用collView的Count属性。它可以与ICollectionView的实现相关联。

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

上面使用的TotalEntityCount描述在这里,

    //
    // 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?

希望帮助