private static string GetRelationshipFromDigitalTwinIds(DigitalTwinsClient client, string sourceTwinId, string targetTwinId)
        {
            string relationshipId = "";
            string sourcedtmi     = "";
            string targetdtmi     = "";

            //obtain the dtmi for the target
            string q = string.Format("SELECT v.$metadata.$model FROM DIGITALTWINS v WHERE $dtId = '{0}' AND IS_PRIMITIVE(v.$metadata.$model)", targetTwinId);

            if (q.Length > 0)
            {
                Pageable <string> result = client.Query(q);

                foreach (string s in result)
                {
                    using (JsonDocument jdoc = JsonDocument.Parse(s))
                    {
                        JsonElement ele = jdoc.RootElement;
                        targetdtmi = ele.GetProperty("$model").ToString();
                    }
                }
            }

            //obtain the dtmi for the source
            q = string.Format("SELECT v.$metadata.$model FROM DIGITALTWINS v WHERE $dtId = '{0}' AND IS_PRIMITIVE(v.$metadata.$model)", sourceTwinId);

            if ((q.Length > 0) && (targetdtmi.Length > 0))
            {
                Pageable <string> result = client.Query(q);

                foreach (string s in result)
                {
                    using (JsonDocument jdoc = JsonDocument.Parse(s))
                    {
                        JsonElement ele = jdoc.RootElement;
                        sourcedtmi = ele.GetProperty("$model").ToString();
                    }
                }

                dtdlInterfaceModel targetDTDL = DigitalTwinModelMethods.GetDTDLModel(client, sourcedtmi);
                if (targetDTDL != null)
                {
                    foreach (dtdlRelationshipModel r in targetDTDL.relationships)
                    {
                        if (r.target == targetdtmi)
                        {
                            relationshipId = r.name;
                            Console.WriteLine("Relationship created: {0}", JsonSerializer.Serialize <dtdlRelationshipModel>(r));
                            break;
                        }
                    }
                }
            }

            return(relationshipId);
        }
        static async Task Main(string[] args)
        {
            DefaultAzureCredential cred   = new DefaultAzureCredential();
            DigitalTwinsClient     client = new DigitalTwinsClient(new Uri("https://mobility-vss.api.wus2.digitaltwins.azure.net"), cred);

            gVehicle = new List <dtdlInterfaceModel>();

            bool loop = true;

            while (loop)
            {
                int    result;
                string c = ReadOptions();

                if (int.TryParse(c, out result))
                {
                    int i = int.Parse(c.ToString());
                    switch (i)
                    {
                    case 0: loop = false;
                        break;

                    case 1: await DigitalTwinMethods.ReadProperty(client);

                        break;

                    case 2: await DigitalTwinMethods.WriteProperty(client);

                        break;

                    case 3: await DigitalTwinModelMethods.ListModels(client);

                        break;

                    case 4: await DigitalTwinModelMethods.GetModel(client);

                        break;

                    case 5: await DigitalTwinModelMethods.GetSchemaType(client);

                        break;

                    case 6: await DigitalTwinModelMethods.CreateModels(client);

                        break;

                    case 7: await DigitalTwinMethods.CreateTwin(client);

                        break;

                    case 8: await DigitalTwinMethods.GetTwin(client);

                        break;

                    case 9: DigitalTwinMethods.DeleteTwin(client);
                        break;

                    case 10: await DigitalTwinMethods.CreateRelationship(client);

                        break;

                    case 11: await DigitalTwinMethods.GetRelationships(client);

                        break;

                    case 12: await DigitalTwinMethods.DeleteRelationship(client);

                        break;

                    default: break;
                    }
                }
            }
        }