[]
        
(Showing Draft Content)

Creating Client Views

ClientView objects represent queries that can be executed on the server. In that regard, they provide the same functionality as queries of Entity Framework and RIA Services. When you start by creating the first ClientView in a newly created context, that's exactly what you get: an EF (or RIA) query that is executed on the server; the resulting entities are fetched to the client and made available for data binding and/or programmatic access on the client. When you continue working on the client, that is, modify some entities on the client and query for more entities, your client views start exhibiting richer behavior that you would not get from mere EF (or RIA) queries:

  • Client views are live. When you modify (or add, or delete) entities on the client, client views are automatically updated to reflect changed data.

  • Client views make use of the C1DataSource client-side data cache. When you create a new client view or change an existing one, querying it does not necessarily require a round-trip to the server. C1DataSource looks in the cache first and uses the cache if the query can be satisfied without going to the server. That happens when a query is repeated, but not only in that case. C1DataSource is smart enough to detect various cases where a query can be satisfied without going to the server.

The starting point for creating client views are the GetItems methods of EntityClientScope (RiaClientScope):


ClientView<Product> products = _scope.GetItems<Product>();


or, in RIA Services (Silverlight):


ClientView<Product> products = _scope.GetItems<Product>("GetProducts");


(in RIA Services you need to specify the name of a query method in your domain service).


Having thus started with a base query, you can then apply filtering and paging to the view. Filtering and paging are operations that are performed on the server (if the data is not found in the cache), so applying them to a ClientView results in another ClientView. You can also apply other LINQ operators to a client view, such as grouping, sorting, and so on. That results in a View, which is the base class of ClientView. It is also a live view but it does not need ClientView functionality because those operators don't need the server; they can be performed entirely on the client.