0

我尝试获取 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 或将其包含在查询中?

4

2 回答 2

2

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

public class MyDomainService : DomainService{
   protected override int Count<T>(IQueryable<T> query) {
        return query.Count();
   }   
}
于 2012-09-11T07:46:36.167 回答
0

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

但是您查看类型为 DomainCollectionView < 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.

I asked a similar question before WCF returned TotalCount -1 but there are Entities, How?

Hope helps

于 2012-09-11T07:47:34.020 回答