Windows 7 Phone Database Rapid Repository – Queries and Views Proposal

Hi All,

I’m about to start working on the query side of the Rapid Repository as I think this will be the most important requirement for the next release (which I am hoping will come pretty soon).

My current plan is to do something fairly simple but I thought I’d publish the idea first in case any would prefer a different implementation.


Proposed implementation


Queries will be done against View Models.

A view model will be a simple class which implements an interface IRapidView (this will enforce that the entity id is captured within the view model class).

The view model will or should be a flattened subset of an entity, perfect for displaying on a page.

An example could be something like the following:

View Model Example
  1. public class CustomerView : IRapidView
  2.     {
  3.         public Guid Id { get; set; }
  4.         public string FirstName { get; set; }
  5.         public string PostCode { get; set; }
  6.     }


To setup the view, at application start up there will be a method similar to the following:

Setting up a View at startup
  1. RapidRepository.AddView<Customer, CustomerView>(c =>
  2.             {
  3.                 return new CustomerView { FirstName = c.FirstName };
  4.             })


Also, I am proposing a filtering feature during setup where linq / lambda can be used to ensure the view filters out any unwanted data – it will look similar to the following:

Filtering the View
  1. RapidRepository.AddView<Customer, CustomerView>(c =>
  2.             {
  3.                 return new CustomerView { FirstName = c.FirstName };
  4.             })
  5.             .Filter<CustomerView>(cv => cv.FirstName != "Sean" && cv.PostCode.Contains("SW1"));


Querying the View

Querying the View will be achieved through a method on the repository that will take the type of view as a generic parameter, this will return a (possibly cached) List<TViewType> that can be queried against using full Linq to Objects.

This will look similar to the following (lambda):

Querying the View
  1. Repository<Customer> customerRepository = new Repository<Customer>();
  3.             List<CustomerView> results = customerRepository.Query<CustomerView>().Where(x => x.PostCode.Contains("SW1")).ToList();


or Linq

Querying the View with linq
  1. List<CustomerView> results = (from c in customerRepository.Query<CustomerView>()
  2.                                          where c.PostCode.Contains("SW1")
  3.                                          select c).ToList();


Why will this be any better than just loading all the entities?


There are a number of reasons why this would be better than getting all on an entity type (how the current release works).

The first being the fact that the view model will contain only the data required for the view, this immediately means less data in memory and less to de-serialise.

The other reasons will include how i intend to store, cache and load the View.

As a basic idea, I’m going to look at storing a view in one view file per type, and have that (optionally) load into the application cache on start up.

The view will then be synchronously managed in memory whilst asynchronously managed within isolated storage.



Anyway, as a really basic overview, that is my current plan, any thoughts, criticisms or ideas would be most welcome.

You can download the current release, source code and test windows 7 phone application from

Kind Regards,

Sean McAlinden.

No Comments