示例#1
0
        /// <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 Task <JsonObject> GetSingleValueAsync(object id, IDictionary <string, string> parameters)
        {
            // Create a query for just this item
            string query = string.Format(
                CultureInfo.InvariantCulture,
                "$filter={0} eq {1}",
                MobileServiceTableUrlBuilder.IdPropertyName,
                TypeExtensions.ToODataConstant(id));

            return(ReadAsync(query, parameters).ContinueWith(t =>
            {
                // Get the first element in the response
                JsonObject obj = t.Result.AsObject();
                if (obj == null)
                {
                    JsonArray array = t.Result.AsArray();
                    if (array != null && array.Count > 0)
                    {
                        obj = array.FirstOrDefault().AsObject();
                    }
                }

                if (obj == null)
                {
                    throw new InvalidOperationException(
                        string.Format(
                            CultureInfo.InvariantCulture,
                            Resources.MobileServiceTables_GetSingleValueAsync_NotSingleObject,
                            (t.Result ?? JsonExtensions.Null()).Stringify()));
                }

                return obj;
            }));
        }
示例#2
0
        /// <summary>
        /// Get an element from a table by its ID.
        /// </summary>
        /// <param name="id">The ID of the element.</param>
        /// <returns>The desired element as JSON object.</returns>
        private async Task <JObject> GetSingleValueAsync(object id)
        {
            // Create a query for just this item
            string query = string.Format(
                CultureInfo.InvariantCulture,
                "$filter={0} eq {1}",
                IdPropertyName,
                TypeExtensions.ToODataConstant(id));

            // Send the query
            JToken response = await this.ReadAsync(query);

            // Get the first element in the response
            JObject obj = response.AsObject();

            if (obj == null)
            {
                JArray array = response.AsArray();
                if (array != null && array.Count > 0)
                {
                    obj = array.FirstOrDefault().AsObject();
                }
            }

            if (obj == null)
            {
                throw new InvalidOperationException(
                          string.Format(
                              CultureInfo.InvariantCulture,
                              Resources.MobileServiceTables_GetSingleValueAsync_NotSingleObject,
                              (response ?? JsonExtensions.Null()).ToString()));
            }

            return(obj);
        }
        /// <summary>
        /// Process constant values.
        /// </summary>
        /// <param name="expression">The expression to visit.</param>
        /// <returns>The visited expression.</returns>
        protected override Expression VisitConstant(ConstantExpression expression)
        {
            if (expression != null)
            {
                string value = TypeExtensions.ToODataConstant(expression.Value);
                this.filter.Append(value);

                this.MarkVisited();
            }
            return(expression);
        }