To correspond to the new RIA Services build we’ve released at Mix, I’ve made some updates to the DomainCollectionView. I updated select API, fixed a few bugs, and updated the sample as well. If you’re not familiar with the DCV, here’s my original post introducing it. For the sake of brevity in this post, I’ll assume you’ve read it.

Breaking Changes

There are a few breaking changes to the API. Most notably, SortPageAndCount has been renamed. It’s a breaking change, but a simple find-replace should set things right again.

  • SortAndPageBy replaces SortPageAndCount
    • SortAndPageBy calls SortBy and PageBy respectively
  • SortBy replaces Sort
    • SortBy applies OrderBy and ThenBy clauses to the query
  • PageBy replaces Page
    • PageBy applies Skip and Take clauses to the query and conditionally requests the TotalEntityCount
  • (All the other query extensions have been removed)

Bug Fixes

There were a few bug fixes that went in to improve compatibility with third-party controls. I’ve tested the DCV against four suites of controls now, and it works well with all of them. As always, let me know when you find issues.

Sample

A common question in response to the first post was how to implement filtering. It turns out to be pretty easy, so I wanted to make it obvious with some updates to my sample.

I’ve updated the UI to include a search field.

image 

The search button now invokes the search command which calls into the OnSearch method in my SampleViewModel.

  private void OnSearch()
  {
    // This makes sure we refresh even if we're already on the first page
    using (this._view.DeferRefresh())
    {
      // This will lead us to re-query for the total count
      this._view.SetTotalItemCount(-1);
      this._view.MoveToFirstPage();
    }
  }

The OnSearch method resets the total item count and refreshes the view; leading us back into our load callback.

  private LoadOperation<SampleEntity> LoadSampleEntities()
  {
    this.CanLoad = false;

    EntityQuery<SampleEntity> query = this._context.GetAllEntitiesQuery();
    if (!string.IsNullOrWhiteSpace(this.SearchText))
    {
      query = query.Where(e => e.String.Contains(this.SearchText));
    }

    return this._context.Load(query.SortAndPageBy(this._view));
  }

To make sure the filter gets applied on the server, we conditionally add a Where clause to our query based on the content of the SearchText.

That covers the new additions to the DomainCollectionView. Once again we’ve put together a small sample running with server-side filtering, sorting, grouping, and paging. Here’re the sample bits. Let me know if you have any questions.

http://code.msdn.microsoft.com/Server-Side-Filtering-737becda