Download this episode

Download Video

Download captions

Download Captions


This week we are meeting again with our big friend Rob Tiffany. This time we talk about NoSQL. It's an easy way to store your data offline on your phone. During this conversation Rob explains what NoSQL is, why you would use it and what the challenges are.

Below are the code samples how to perform the CRUD operations on your in memory classes.

Define Table schema (Entity)

    publicint CustomerId { get; set; }
    publicstring FirstName { get; set; }
    publicstring LastName { get; set; }

Define Table (Generic List to hold collection of Customer objects)

publicstaticList<Customer> Customers { get; set; }

Create Table

Customers = newList<Customer>();

Save Table

publicstaticasyncTask SaveChanges<T>(T collection, String tableName)
    var file = awaitApplicationData.Current.LocalFolder.CreateFileAsync(tableName, CreationCollisionOption.ReplaceExisting);
    var outStream = await file.OpenStreamForWriteAsync();
    var serializer = newDataContractJsonSerializer(typeof(T));
    serializer.WriteObject(outStream, collection);
    await outStream.FlushAsync();

Calling the Save Table Method

await SaveChanges<List<Customer>>(Customers, "Customer");

Load Table

publicstaticasyncTask<T> LoadTable<T>(string tableName)
    StorageFile file = awaitApplicationData.Current.LocalFolder.GetFileAsync(tableName);
    Stream stream = await file.OpenStreamForReadAsync();
    DataContractJsonSerializer serializer = newDataContractJsonSerializer(typeof(T));
    T table = (T)serializer.ReadObject(stream);
    return table;

Calling the Load Table Method

Customers = await LoadTable<List<Customer>>("Customer");

Insert Customers

    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 inTableService.Customers
            select c;
CustomersList.ItemsSource = query.ToList();

Tweet to @robtiffany or @mahoekst



Available formats for this video:

Actual format may change based on video formats available and browser capability.

    The Discussion

    • User profile image

      Cool topic. It took me a while to realize that all there seems to be about this approach is in the SaveChanges/LoadTable methods provided.

    • User profile image

      Nice, I like this topic.
      Thanks for the code examples & the overview video.

      Please provide some more context for other (LOB), Website applications though.
      Or apps that need to log a lot, these could benefit a lot from NoSQL approach.

      How should we setup, which products does MS provide? Is there a whitepaper on setting these things up, outside WP.

    • User profile image


      What do you mean by other (LOB), Website applications?

    • User profile image

      Like the title "IWP71" --> WP 7.1

    Comments closed

    Comments have been closed since this content was published more than 30 days ago, but if you'd like to send us feedback you can Contact Us.