简体   繁体   English

在指针列上解析查询

[英]Parse query on pointer column

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. 我有一个xamarin Android项目,使用Parse.com作为后端。 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). 我有两个表(或类),一个包含一个信标列表(称为信标),另一个包含一个类别列表(称为BeaconCat)。 The headings of the table for the beacons class looks like: beacons类的表标题如下:

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

The headings of the BeaconCat class looks like: BeaconCat类的标题如下:

   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. 我要做的是,运行一个传递“次要”数字的查询,在第一个表中查找该数字,并在第二个表中返回category列的值。

So in the example above, i want to pass in the minor of 200, and get back the string 'sports'. 因此,在上面的示例中,我想传递200的未成年人,并返回字符串'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. 任何帮助对此表示赞赏。

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");
            }

        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM