Challenger
Challenger

Reputation: 251

Retrieve Data from Windows Azure Storage

How do I query my Windows Azure Storage such as:

(SELECT Name FROM User WEHRE DeviceID = App.Current.DeviceID)  

Tried this, didn't seem to work

var Name = await App.MobileService.GetTable<User>()
    .Select(User => User.Name)
    .Where(User => User.DeviceID == App.Current.DeviceID); 

But I could query the table based on the id

 var Name = await App.MobileService.GetTable<User>().LookupAsync(id);

Is there a similar method to query the table based on string(eg. phone DeviceID) instead of an integer id?

User Class

public class User
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string DeviceID { get; set; }
    }

Upvotes: 2

Views: 1629

Answers (1)

carlosfigueira
carlosfigueira

Reputation: 87218

The result of the Where method is still a query object, it isn't the object itself yet. You need to call one of the ToListAsync or ToEnumerableAsync to actually make the request:

var Name = (await App.MobileService.GetTable<User>()
    .Where(User => User.DeviceID == App.Current.DeviceID)
    .Select(User => User.Name)
    .ToEnumerableAsync()).FirstOrDefault();

Upvotes: 2

Related Questions