/// <summary> /// Get an element from a table by its id. /// </summary> /// <param name="id"> /// The id of the element. /// </param> /// <param name="parameters"> /// A dictionary of user-defined parameters and values to include in /// the request URI query string. /// </param> /// <returns> /// The desired element as JSON object. /// </returns> private async Task <JObject> GetSingleValueAsync(object id, IDictionary <string, string> parameters) { Debug.Assert(id != null); // Create a query for just this item string query = string.Format( CultureInfo.InvariantCulture, "$filter=({0} eq {1})", MobileServiceSystemColumns.Id, FilterBuildingExpressionVisitor.ToODataConstant(id)); // Send the query QueryResult response = await this.ReadAsync(query, parameters, MobileServiceFeatures.TypedTable); return(GetSingleValue(response)); }
/// <summary> /// Get an element from a table by its id. /// </summary> /// <param name="id"> /// The id of the element. /// </param> /// <param name="parameters"> /// A dictionary of user-defined parameters and values to include in /// the request URI query string. /// </param> /// <returns> /// The desired element as JSON object. /// </returns> private async Task <string> GetSingleValueAsync(object id, IDictionary <string, string> parameters) { Debug.Assert(id != null); // Create a query for just this item string query = string.Format( CultureInfo.InvariantCulture, "$filter={0} eq {1}", MobileServiceUrlBuilder.IdPropertyName, FilterBuildingExpressionVisitor.ToODataConstant(id)); // Send the query JToken response = await this.ReadAsync(query, parameters); // Get the first element in the response JObject obj = response as JObject; if (obj == null) { JArray array = response as JArray; if (array != null && array.Count > 0) { obj = array.FirstOrDefault() as JObject; } } if (obj == null) { string responseStr = response != null?response.ToString() : "null"; throw new InvalidOperationException( string.Format( CultureInfo.InvariantCulture, Resources.MobileServiceTable_NotSingleObject, responseStr)); } return(obj.ToString()); }