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

NoSQL on Windows
Tagged on:                 

Rob Tiffany

Rob is a writer, teacher, speaker, world traveller and undersea explorer. He's also a thought leader in the areas of enterprise mobility and the Internet of Things.

One thought on “NoSQL on Windows

  • January 27, 2014 at 4:36 am

    Does I can use this For WinRT.?
    in WinRT file.OpenStreamForWriteAsync(); I am not able to find this stream.

    Thank you,
    -Jitendra Jadav


Leave a Reply

Your email address will not be published.

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