0

I've already kind of asked this question, but i'm going to try to be more specific in the hope of being a little clearer.

I have a xamarin Android project, using Parse.com as the back end. I have two tables (or classes), one which contains a list of beacons (called Beacons), and one which contains a list of categories (called BeaconCat). The headings of the table for the beacons class looks like:

ObjectID   |  minor  | major  |  CatID (this is the 'pointer' column to BeaconCat)
111111     |  200     |  999  |   12345

The headings of the BeaconCat class looks like:

   ObjectID  |  Category
    12345    |   Sports

All i'm trying to do, is run a query that passes in a 'minor' number, that number gets looked up in the first table, and returns the value of the category column in the second table.

So in the example above, i want to pass in the minor of 200, and get back the string 'sports'.

Seems like it should be very easy but i'm really struggling.

I've been trying variations of the following:

public async void getBeaconCat(Int32 minor)
  {
    try{

            var innerQuery = ParseObject.GetQuery("Beacons");
            innerQuery.WhereEqualTo("minor", minor);
            innerQuery.Include("CatID");

            var newQuery = ParseObject.GetQuery("BeaconCat");
            newQuery.WhereMatchesQuery("Category", innerQuery);

            IEnumerable<ParseObject> Myresults = await innerQuery.FindAsync();

            foreach (var result in Myresults)
             {

                var category = result.Get<string>("Category");
                Console.WriteLine ("Category is " + category);
             }

            }
                catch{
                    Console.WriteLine ("There was a problem fetching data from parse");
            }

        }

Anything i try just seems to go straight to the catch and not return a string value.

Any help on this appreciated.

1
  • Could you use debugging to find out which line the error occurs? Or alternatively alternate each line of code in the try{} with Console.WriteLine("# identifying the step") so you can tell which line stuff is going wrong? Commented Aug 21, 2014 at 14:30

1 Answer 1

1

OK, finally got it. This works:

public async Task getBeaconCat(Int32 minor)
        {
            try{


                var innerQuery = ParseObject.GetQuery("Beacons").WhereEqualTo("minor", minor).Include("CatID").Include("Category");

                IEnumerable<ParseObject> MyFirstResults = await innerQuery.FindAsync();
                foreach (var result in MyFirstResults)
                {
                    var catObject = result.Get<ParseObject>("CatID");

                    var category = catObject.Get<string>("Category");
                    Console.WriteLine ("The category is......... " + category);
                    return category;

                }

            }
            catch{
                Console.WriteLine ("There was a problem fetching data from parse");
            }

        }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.