Thursday, December 26, 2013

Fetching Windows Azure Mobile Service Data


Inserting data is one half of a story, which is incomplete until you reveal the other half. Reading data is the other half. Windows Azure Mobile Service provides various ways of doing that. In this post however, we will be focusing on firing Linq to fetch data.

For the most part, we will be continuing from the previous posts where we’ve created a mobile service and consumed it in a Windows 8 Store application. We will use the same app, rather modify it a bit to meet the new purpose.

I have added one more button in the UI which fetch the data as per the text entered in the above text box. If nothing is entered in the text box, it fetches all the data from that table.

image

I have also added a list box to show the fetched results. On the click of “Filtered Data”, following code is written.

   1: private async void Button_Click_2(object sender, RoutedEventArgs e)
   2: {
   3:    var text = UserCommentText.Text.Trim();
   4:    List<Comment> itemColl = null;
   5:    IMobileServiceTable<Comment> table = MobileService.GetTable<Comment>();
   6:  
   7:    //Fetching data from cloud
   8:    itemColl = text == string.Empty ? 
   9:                await table.ToListAsync() :
  10:                await table.Where(x => x.usercomment.Contains(text)).ToListAsync();
  11:  
  12:    foreach (var item in itemColl)
  13:    {
  14:        showData.Items.Add(item.usercomment);
  15:    }
  16:  
  17: }

We first created an object table of type “Mobile Service Table” we then wrote the link expressions which serve our purpose. Finally we call “ToListAsync()” extension method that would actually perform the GET operation based on the link expression written.

Well, this is how we can read the data from the Mobile service.
You can download the sample project, The Windows 8 Store App from here.

Happy Reading!!

Share this post

0 comments

:) :-) :)) =)) :( :-( :(( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ :-$ (b) (f) x-) (k) (h) (c) cheer

 
© 2013 Neelesh Vishwakarma
Posts RSS Comments RSS
Back to top