user2313394
user2313394

Reputation: 21

parse.com c# query, how to get the results?

I'm trying to read some data from the parse.com database in the cloud in a c# .net application but i'm stuck at getting at the values I'm after. The code as it stands is called on app launch (for now):

  Console.WriteLine("called app launch");

  var query = ParseObject.GetQuery("Maintenances")
        .WhereEqualTo("Sent", "true");
  IEnumerable<ParseObject> results = await query.FindAsync();



  foreach (var record in results)
  {
      Console.WriteLine("in for each");
      var docket = record.Get<String>("Docket");
      Console.WriteLine(docket);
  }

So i'm querying a Class called "Maintenances" where the field "Sent" is "true". Then for each "record" in the IEnumerable named "results" I'm attempting to write out to the console for debugging purposes for now. However, i'm not getting the correct data in the var "docket" with errors such as

"Unable to cast object of type 'System.Collections.Generic.List`1[System.Object]' to type 'System.String'."

being spat out. But, when in break mode (in visual studio 2012 express) I hover over "record" I can see that record is a Parse.ParseObject and then if I click on the Results View (which mentions "Expanding the Results View will enumerate the IEnumerable") I can see all the Keys within the class and their correct corresponding values!

I'm thinking I need to "enumerate the IEnumerable" in my code and then dig out the correct value but I'm not sure how to do this. Can anybody help / point me to a good c# tutorial using the Parse.com SDK with queries and using the results it would be much appreciated.

Upvotes: 2

Views: 4242

Answers (1)

Umar Abbas
Umar Abbas

Reputation: 4161

Try to convert your code in a method

public async void getdata(String Z,bool b)
            {
                var query = ParseObject.GetQuery("Maintenances")
           .WhereEqualTo("z", "b");
                IEnumerable<ParseObject> results = await query.FindAsync();



                foreach (var record in results)
                {
                    Console.WriteLine("in for each");
                    var docket = record.Get<String>("Docket");
                    Console.WriteLine(docket);
                }
            }

Upvotes: 3

Related Questions