在指针列分析查询 [英] 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.
我有一个xamarin Android项目,使用Parse.com作为后端。我有两个表(或类),其中一个包含的信标的列表(称为信标),和一种含有一个类别列表(称为BeaconCat)。表中的信标类的标题是这样的:
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
在BeaconCat类的标题是这样的:
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.
所以在上面的例子中,我想在200次传球,并取回字符串'运动'。
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.
在这个AP preciated任何帮助。
Any help on this appreciated.
推荐答案
OK,终于得偿所愿。这工作:
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");
}
}
这篇关于在指针列分析查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!