コード例 #1
0
        /// <summary>
        /// Performs a query.
        /// </summary>
        /// <typeparam name="TModel">The type of object to query.</typeparam>
        /// <param name="query">The query parameters as a LINQ expression.</param>
        /// <param name="offset">The offset of the query.</param>
        /// <param name="count">The count of the query results.</param>
        /// <param name="expandProperties">An property traversal for which to expand upon.</param>
        /// <returns>Returns a Bundle containing the data.</returns>
        public Bundle Query <TModel>(Expression <Func <TModel, bool> > query, int offset, int?count, string[] expandProperties = null, Guid?queryId = null, ModelSort <TModel>[] orderBy = null) where TModel : IdentifiedData
        {
            // Map the query to HTTP parameters
            var queryParms = QueryExpressionBuilder.BuildQuery(query, true).ToList();

            queryParms.Add(new KeyValuePair <string, object>("_offset", offset));

            if (count.HasValue)
            {
                queryParms.Add(new KeyValuePair <string, object>("_count", count));
            }

            if (expandProperties != null && expandProperties.Length > 0)
            {
                queryParms.AddRange(expandProperties.Select(i => new KeyValuePair <string, object>("_expand", i)));
            }

            if (queryId.HasValue)
            {
                queryParms.Add(new KeyValuePair <string, object>("_queryId", queryId.ToString()));
            }

            if (orderBy != null)
            {
                foreach (var itm in orderBy)
                {
                    queryParms.Add(new KeyValuePair <string, object>("_orderBy", QueryExpressionBuilder.BuildSortExpression(itm)));
                }
            }

            // Resource name
            string resourceName = typeof(TModel).GetTypeInfo().GetCustomAttribute <XmlTypeAttribute>().TypeName;

            // The HDSI uses the XMLName as the root of the request
            var retVal = this.Client.Get <Bundle>(resourceName, queryParms.ToArray());

            // Return value
            return(retVal);
        }
コード例 #2
0
        /// <summary>
        /// Perform a query
        /// </summary>
        public AmiCollection Query <TModel>(Expression <Func <TModel, bool> > expression, int offset, int?count, out int tr, Guid?queryId = null, ModelSort <TModel>[] orderBy = null)
        {
            // Map the query to HTTP parameters
            var queryParms = QueryExpressionBuilder.BuildQuery(expression, true).ToList();

            queryParms.Add(new KeyValuePair <string, object>("_offset", offset));

            if (count.HasValue)
            {
                queryParms.Add(new KeyValuePair <string, object>("_count", count));
            }

            if (queryId.HasValue)
            {
                queryParms.Add(new KeyValuePair <string, object>("_queryId", queryId.ToString()));
            }

            if (orderBy != null)
            {
                foreach (var itm in orderBy)
                {
                    queryParms.Add(new KeyValuePair <string, object>("_orderBy", QueryExpressionBuilder.BuildSortExpression(itm)));
                }
            }

            // Resource name
            string resourceName = typeof(TModel).GetTypeInfo().GetCustomAttribute <XmlRootAttribute>()?.ElementName
                                  ?? typeof(TModel).GetTypeInfo().GetCustomAttribute <XmlTypeAttribute>()?.TypeName;

            // The HDSI uses the XMLName as the root of the request
            var retVal = this.Client.Get <AmiCollection>(resourceName, queryParms.ToArray());

            tr = retVal.Size;

            // Return value
            return(retVal);
        }