Exemple #1
0
        /// <summary>
        /// The select and expand query options.
        /// </summary>
        /// <param name="query">
        /// The OData aware query.
        /// </param>
        /// <param name="selectText">
        /// The $select parameter text.
        /// </param>
        /// <param name="expandText">
        /// The $expand parameter text.
        /// </param>
        /// <param name="entitySetName">
        /// The entity set name.
        /// </param>
        /// <typeparam name="T">
        /// The query type param
        /// </typeparam>
        /// <returns>
        /// The <see cref="IEnumerable{ISelectExpandWrapper}"/> selection result in specific format.
        /// </returns>
        public static IEnumerable <ISelectExpandWrapper> SelectExpand <T>(
            this ODataQuery <T> query,
            string selectText    = null,
            string expandText    = null,
            string entitySetName = null)
        {
            SelectExpandHelper <T> helper = new SelectExpandHelper <T>(
                new ODataRawQueryOptions {
                Select = selectText, Expand = expandText
            },
                query,
                entitySetName);

            helper.AddAutoSelectExpandProperties();

            var result = helper.Apply(query);

            // In case of SelectExpand ,ethod was called to convert to ISelectExpandWrapper without actually applying $select and $expand params
            if (result == query && selectText == null && expandText == null)
            {
                return(SelectExpand(query, "*", expandText, entitySetName));
            }

            return(result.OfType <ISelectExpandWrapper>());
        }
        private static IQueryable SelectExpandInternal <T>(ODataQuery <T> query, string selectText, string expandText,
                                                           string entitySetName)
        {
            SelectExpandHelper <T> helper = new SelectExpandHelper <T>(
                new ODataRawQueryOptions {
                Select = selectText, Expand = expandText
            },
                query,
                entitySetName);

            helper.AddAutoSelectExpandProperties();

            var result = helper.Apply(query);

            // In case of SelectExpand ,method was called to convert to ISelectExpandWrapper without actually applying $select and $expand params
            if (result == query && selectText == null && expandText == null)
            {
                return(SelectExpandInternal(query, "*", expandText, entitySetName));
            }

            return(result);
        }