Cloud Tables

A Cloud Table provides an abstraction layer over Windows Azure Table Storage. It provides the following features:
  • Use POCO types instead of TableEntity.
  • Direct CRUD operations without TableOperation.
  • Query using predicates instead of TableQuery.


The following code creates a "customers" table for saving a Customer POCO type. The first parameter specifies the name of the identifier field that can uniquely identify the entity. The field will be mapped to the row key of a Windows Azure Table. If you want to use both parition keys and row keys, you can specify two separate fields as well.
Table<Customer> storage = new Table<Customer>("ID", "[your storage connection string]", "customers", false);

To insert a new Customer instance to the table:
storage.Insert(new Customer { ID = 100, Name = "This is a customer.", Value = 123.456, Time = time});

To read the customer back:
var customer = storage.Read("100");

To update the customer, simply update its properties and write it back:
customer.Name = "This is a new name";

And finally, to delete the customer, use:

Automatic Cache

Cloud Table provides an automatic caching layer in front of Windows Azure Table Storage. Cloud Table provides two types of caches, both of which are managed automatically by the library:
  • A lazy-load cache. Table rows are loaded to cache as they are being retrieved so that they can be retrieved faster by later queries.
  • A paged cache. When you use the List() method with a key range, the returned records are cached as a whole page. This allows you to page through Table Storage records at a faster speed.

To leverage caching features, provide a DataCache instance to the Table instance using a constructor overload:
Table<Customer> customers = new Table<Customer>("ID", "[your storage connection string]", "customers", new DataCache());

Then, you simply read/write table records as usual. Cache is automatically maintained. You can configure your cache cluster to apply expiration policies and eviction polices as needed to match with your scenario needs.

When cache is enabled. Queries by id range are automatically cached. This feature essentially allows you to load records by pages into the cache. Loading by page may provide better performance in some scenarios comparing to lazy-load. Loading a page is easy:
customers = storage.List("50", "59");


  • The Update method employs optimistic concurrency. The updated item has to present the same ETag as what is on the newest item, otherwise the operation will fail. The Replace method, on the other hand, forces to replace the existing item with the new item.
  • To query table records with a filter, you can supply a lambda expression to the List method. For example, to query all customers whose name starts with "A", use:
var list = storage.List(c => c.Name.StartsWith("A"));

Last edited Nov 27, 2013 at 7:33 AM by Haishi, version 4