/// <summary>
        /// Projects the element of this query into a new form.
        /// </summary>
        /// <typeparam name="TResult">The type of the value returned by selector.</typeparam>
        /// <param name="selector">A lambda expression that indicates the property returns.</param>
        /// <returns>A <see cref="Microsoft.OData.Client.DataServiceQuerySingle{T}" /> whose element is the result of invoking the transform function on the element of source.</returns>
        public DataServiceQuerySingle <TResult> Select <TResult>(Expression <Func <TElement, TResult> > selector)
        {
            if (this.Query == null)
            {
                this.Query = Context.CreateSingletonQuery <TElement>(GetPath(null));
            }

            return(new DataServiceQuerySingle <TResult>((DataServiceQuery <TResult>)Query.Select(selector), true));
        }
Example #2
0
        public DataServiceQuery CreateObjectQuery(string entityName, CriteriaOperator filter, Dictionary <string, string> properties)
        {
            var entityType = GetTypeDefinition(entityName);


            DataServiceQuery query = CreateQuery(entityName);
            bool             hasIsDeletedProperty = HasField(query.ElementType, "IsDeleted");

            if (hasIsDeletedProperty)
            {
                BinaryOperator deletedFilter = new BinaryOperator("IsDeleted", false);
                if ((object)filter == null)
                {
                    filter = deletedFilter;
                }
                else
                {
                    filter = filter & deletedFilter;
                }
            }

            if ((object)filter != null)
            {
                query = DataServiceQueryTranslator.Translate(query, filter);
            }

            if (properties != null)
            {
                var propertyNames = entityType.StructuralProperties().Where(p => !properties.ContainsKey(p.Name)).Select(p => p.Name).ToList();
                propertyNames.ForEach(p => properties.Add(p, p));

                var fetchingProperties = properties.Select(addition => addition.Value + " AS " + addition.Key);
                query = query.Select("new(" + string.Join(",", fetchingProperties) + ")") as DataServiceQuery;
            }

            return(query);
        }