コード例 #1
0
        /// <summary>
        /// Convert EntityReference to WebApi NavigationUrl
        /// </summary>
        /// <param name="entityReference">EntityReference</param>
        /// <param name="organizationMetadata">Instance metadata store</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">When EntityReference is null</exception>
        public static string ToNavigationLink(this EntityReference entityReference,
                                              IWebApiMetadataService organizationMetadata)
        {
            if (entityReference is null)
            {
                throw new ArgumentNullException(nameof(entityReference));
            }

            var logicalName    = entityReference.LogicalName;
            var collectionName = organizationMetadata.GetEntitySetName(logicalName);

            // If alternate keys not present
            if (entityReference.KeyAttributes.Any() != true)
            {
                return($"{collectionName}({entityReference.Id})");
            }

            // Else If alternate keys present
            var keysPairList = new List <string>();

            foreach (var(key, value) in entityReference.KeyAttributes)
            {
                if (value is int)
                {
                    keysPairList.Add($"{key}={value}");
                }
                else
                {
                    keysPairList.Add($"{key}='{value}'");
                }
            }

            return($"{collectionName}({string.Join("&", keysPairList)})");
        }
コード例 #2
0
        /// <summary>
        /// Convert EntityReference to WebApi NavigationUrl
        /// </summary>
        /// <param name="entityReference">EntityReference</param>
        /// <param name="organizationMetadata">Instance metadata store</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">When EntityReference is null</exception>
        public static string ToNavigationLink(this EntityReference entityReference,
                                              IWebApiMetadataService organizationMetadata)
        {
            if (entityReference is null)
            {
                throw new ArgumentNullException(nameof(entityReference));
            }

            var logicalName    = entityReference.LogicalName;
            var collectionName = organizationMetadata.GetEntitySetName(logicalName);

            // If alternate keys not present
            if (entityReference.KeyAttributes.Any() != true)
            {
                return($"{collectionName}({entityReference.Id})");
            }

            // Else If alternate keys present
            var keys = entityReference.KeyAttributes
                       .Select(kvp => $"{kvp.Key}='{kvp.Value}'");

            return($"{collectionName}({string.Join("&", keys)})");
        }