Accessing ADT from .NET, I am trying to obtain the number of a particular relationship each of my nodes has. For example, there are a number of people nodes and each person could have 1, 2 or more friends (a relationship of type friend). I want to retrieve a list of the node name (e.g. John) and the number of friends they have, e.g.:
John, 3 Harry, 2 Frank, 4
However, when you use JOIN in ADT, it seems you have to combine it with WHERE and use a single $dtId. So for example,
SELECT COUNT() FROM DIGITALTWINS twin JOIN parent RELATED twin.Friend WHERE twin.$dtId= 'John'
Only retrives the number of Friend relationships for this one node.
From the documentation, it seems it is possible to retrieve more than one node when using JOIN by using keyword IN e.g. (copying from docs)
SELECT Room
FROM DIGITALTWINS Floor
JOIN Room RELATED Floor.contains
WHERE Floor.$dtId IN ['floor1','floor2', ..'floorn']
AND Room. Temperature > 72
AND IS_OF_MODEL(Room, 'dtmi:com:contoso:Room;1')
However, when I apply this with variations such as:
SELECT Count() AS what FROM DIGITALTWINS twin JOIN parent RELATED twin.HasDocument WHERE twin.$dtId IN ['John', 'Harry']
I don't get what I'm looking for.
Ultimately, in c#. I would like to loop through the results with something like: await foreach (BasicDigitalTwin twin in queryResult) {}, saving to a List (where node contains nodename and numberoffriends properties.
Any help much appreciated. Maybe I need something entirely different, not a join.