ObjectQuery<T>.SelectValue(String, ObjectParameter[]) ObjectQuery<T>.SelectValue(String, ObjectParameter[]) ObjectQuery<T>.SelectValue(String, ObjectParameter[]) ObjectQuery<T>.SelectValue(String, ObjectParameter[]) Method


Limits the query results to only the property specified in the projection.

generic <typename TResultType>
 System::Data::Objects::ObjectQuery<TResultType> ^ SelectValue(System::String ^ projection, ... cli::array <System::Data::Objects::ObjectParameter ^> ^ parameters);
public System.Data.Objects.ObjectQuery<TResultType> SelectValue<TResultType> (string projection, params System.Data.Objects.ObjectParameter[] parameters);
member this.SelectValue : string * System.Data.Objects.ObjectParameter[] -> System.Data.Objects.ObjectQuery<'ResultType>
Public Function SelectValue(Of TResultType) (projection As String, ParamArray parameters As ObjectParameter()) As ObjectQuery(Of TResultType)

Type Parameters


The type of the ObjectQuery<T> returned by the SelectValue<TResultType>(String, ObjectParameter[]) method.


String String String String

The projection list.


An optional set of query parameters that should be in scope when parsing.



A new ObjectQuery<T> instance of a type compatible with the specific projection. The returned ObjectQuery<T> is equivalent to the original instance with SELECT VALUE applied.



This example is based on the AdventureWorks Sales Model. The example creates a new ObjectQuery<T> that contains results that are a sequence of ProductID values projected from the results of the existing query.

using (AdventureWorksEntities context =
    new AdventureWorksEntities())
    string queryString =
        @"SELECT VALUE product FROM 
            AdventureWorksEntities.Products AS product";

    ObjectQuery<Product> productQuery1 =
        new ObjectQuery<Product>(queryString,
            context, MergeOption.NoTracking);

    ObjectQuery<Int32> productQuery2 =

    foreach (Int32 result in productQuery2)
        Console.WriteLine("{0}", result);
Using context As New AdventureWorksEntities()
    Dim queryString As String = "SELECT VALUE product FROM AdventureWorksEntities.Products AS product"

    Dim productQuery1 As New ObjectQuery(Of Product)(queryString, context, MergeOption.NoTracking)

    Dim productQuery2 As ObjectQuery(Of Int32) = productQuery1.SelectValue(Of Int32)("it.ProductID")

    For Each result As Int32 In productQuery2
        Console.WriteLine("{0}", result)
End Using


SelectValue is used to return values that are simple types, entity types, or complex types. Use the Select method for projections that require a row type instead of a value type. For more information, see Object Queries.

The SelectValue method applies the projection specified by the projection parameter. The ObjectQuery<T> returned by the SelectValue method must be of a value type that is compatible with the projection and must be the same type as the type of SelectValue.

Applies to

See also