/// <summary>Limits the query results to only the property specified in the projection.</summary>
 /// <returns>
 /// A new <see cref="T:System.Data.Entity.Core.Objects.ObjectQuery`1" /> instance of a type compatible with the specific projection. The returned
 /// <see cref="T:System.Data.Entity.Core.Objects.ObjectQuery`1" />
 /// is equivalent to the original instance with SELECT VALUE applied.
 /// </returns>
 /// <param name="projection">The projection list.</param>
 /// <param name="parameters">An optional set of query parameters that should be in scope when parsing.</param>
 /// <typeparam name="TResultType">
 /// The type of the <see cref="T:System.Data.Entity.Core.Objects.ObjectQuery`1" /> returned by the
 /// <see cref="M:System.Data.Entity.Core.Objects.ObjectQuery`1.SelectValue``1(System.String,System.Data.Entity.Core.Objects.ObjectParameter[])" />
 /// method.
 /// </typeparam>
 /// <exception cref="T:System.ArgumentNullException"> projection  is null or parameters  is null.</exception>
 /// <exception cref="T:System.ArgumentException">The  projection  is an empty string.</exception>
 public ObjectQuery <TResultType> SelectValue <TResultType>(
     string projection,
     params ObjectParameter[] parameters)
 {
     Check.NotEmpty(projection, nameof(projection));
     Check.NotNull <ObjectParameter[]>(parameters, nameof(parameters));
     this.QueryState.ObjectContext.MetadataWorkspace.ImplicitLoadAssemblyForType(typeof(TResultType), Assembly.GetCallingAssembly());
     return(new ObjectQuery <TResultType>(EntitySqlQueryBuilder.SelectValue(this.QueryState, this.Name, projection, parameters, typeof(TResultType))));
 }
Exemplo n.º 2
0
        /// <summary>Limits the query results to only the property specified in the projection.</summary>
        /// <returns>
        /// A new <see cref="T:System.Data.Entity.Core.Objects.ObjectQuery`1" /> instance of a type compatible with the specific projection. The returned
        /// <see
        ///     cref="T:System.Data.Entity.Core.Objects.ObjectQuery`1" />
        /// is equivalent to the original instance with SELECT VALUE applied.
        /// </returns>
        /// <param name="projection">The projection list.</param>
        /// <param name="parameters">An optional set of query parameters that should be in scope when parsing.</param>
        /// <typeparam name="TResultType">
        /// The type of the <see cref="T:System.Data.Entity.Core.Objects.ObjectQuery`1" /> returned by the
        /// <see
        ///     cref="M:System.Data.Entity.Core.Objects.ObjectQuery`1.SelectValue``1(System.String,System.Data.Entity.Core.Objects.ObjectParameter[])" />
        /// method.
        /// </typeparam>
        /// <exception cref="T:System.ArgumentNullException"> projection  is null or parameters  is null.</exception>
        /// <exception cref="T:System.ArgumentException">The  projection  is an empty string.</exception>
        public ObjectQuery <TResultType> SelectValue <TResultType>(string projection, params ObjectParameter[] parameters)
        {
            Check.NotEmpty(projection, "projection");
            Check.NotNull(parameters, "parameters");

            // SQLPUDT 484974: Make sure TResultType is loaded.
            QueryState.ObjectContext.MetadataWorkspace.ImplicitLoadAssemblyForType(typeof(TResultType), Assembly.GetCallingAssembly());

            return
                (new ObjectQuery <TResultType>(
                     EntitySqlQueryBuilder.SelectValue(QueryState, Name, projection, parameters, typeof(TResultType))));
        }
        /// <summary>
        ///   This query-builder method creates a new query whose results are a sequence
        ///   of values projected from the results of this query.
        /// </summary>
        /// <param name="projection">
        ///   The projection list.
        /// </param>
        /// <param name="parameters">
        ///   An optional set of query parameters that should be in scope when parsing.
        /// </param>
        /// <returns>
        ///   a new ObjectQuery instance.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///   If either argument is null.
        /// </exception>
        /// <exception cref="ArgumentException">
        ///   If the projection list command text is empty.
        /// </exception>
        public ObjectQuery <TResultType> SelectValue <TResultType> (string projection, params ObjectParameter[] parameters)
        {
            EntityUtil.CheckArgumentNull(projection, "projection");
            EntityUtil.CheckArgumentNull(parameters, "parameters");

            if (StringUtil.IsNullOrEmptyOrWhiteSpace(projection))
            {
                throw EntityUtil.Argument(System.Data.Entity.Strings.ObjectQuery_QueryBuilder_InvalidProjectionList, "projection");
            }

            // SQLPUDT 484974: Make sure TResultType is loaded.
            this.QueryState.ObjectContext.MetadataWorkspace.ImplicitLoadAssemblyForType(typeof(TResultType), System.Reflection.Assembly.GetCallingAssembly());

            return(new ObjectQuery <TResultType>(EntitySqlQueryBuilder.SelectValue(this.QueryState, this.Name, projection, parameters, typeof(TResultType))));
        }