Wednesday, February 16, 2011

IncludeTotalCount Silverlight RIA Service (Server Side Paging)

If you are using Server Side Paging (may be at database or service end) and returning limited set of results you may find it difficult to get the TotalItemCount of your entities.

But the answer is simple enough:

//Enable IncludeTotalCount to true in View/ViewModel before calling the data context to load data

EntityQuery query = _assessmentContext.XQuery(1, this._pageIndex, this._pageSize);
query.IncludeTotalCount = true; // Specify that service need to collect the total item count somehow

//Load your Entity asynchronously here

// Enable your service to set an out parameter for total item count:

public IQueryable Xs(int xID, int pageIndex, int pageSize, out int totalCount)
        totalCount = 110;

That's it you are done you can now get the total item count in the load operation result:

private void XsLoadingCompleted(LoadOperation lo)
            this.BusyContent = ApplicationStrings.LoadingXs;

            if (!lo.HasError)
                this.XItemCount = lo.TotalEntityCount; // total item count that you set through the out parameter //in your domain service.


  1. This comment has been removed by a blog administrator.

  2. Hey, great tip! Thanks a lot.