NoSQL on Windows

In this week’s episode of “Inside Windows Phone,” Matthijs Hoekstra and I discuss the use of NoSQL.

When building mobile apps for the enterprise, an offline data store is absolutely essential so that users can keep working in the absence of wireless connectivity.  In addition to SQLite and SQLCE, NoSQL is a great option to consider in order to achieve your goals with local data storage.

Below are some code snippets I created to get you started:

Define Table schema (Entity)
public sealed class Customer
    public int CustomerId { getset; }
    public string FirstName { getset; }
    public string LastName { getset; }

Define Table (Generic List to hold collection of Customer objects)
public static List<Customer> Customers { getset; }


Create Table
Customers = new List<Customer>();


Save Table
public static async Task SaveChanges<T>(T collection, String tableName)
    var file = awaitApplicationData.Current.  LocalFolder.CreateFileAsync(tableName, CreationCollisionOption.ReplaceExisting);
    var outStream = await file.OpenStreamForWriteAsync();
    var serializer = new DataContractJsonSerializer(typeof(T));
    serializer.WriteObject(outStream, collection);
    await outStream.FlushAsync();
Calling the Save Table Method
await SaveChanges<List<Customer>>(Customers, “Customer”);
Load Table
public static async Task<T> LoadTable<T>(string tableName)
    StorageFile file = awaitApplicationData.Current.
    Stream stream = await file.OpenStreamForReadAsync();
    DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T));
    T table = (T)serializer.ReadObject(stream);
    return table;
Calling the Load Table Method
Customers = await LoadTable<List<Customer>>(“Customer”);
INSERT Customers
Customers.Add(new Customer
    CustomerId = 1,
    FirstName = “Andy”,
    LastName = “Wigley”
UPDATE Customers
foreach (var item in Customers.Where((c) => c.CustomerId == 2))
    item.FirstName = “Mike”;
DELETE Customers
Customers.RemoveAll((c) => c.CustomerId == 2);
SELECT Customers
var query = from c in TableService.Customers
            select c;
CustomersList.ItemsSource = query.ToList();


Have fun!

Sharing my knowledge and helping others never stops, so connect with me on my blog at , follow me on Twitter at and on LinkedIn at

1 thought on “NoSQL on Windows”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.