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


Limits the query results to only the properties that are defined in the specified projection.

 System::Data::Objects::ObjectQuery<System::Data::Common::DbDataRecord ^> ^ Select(System::String ^ projection, ... cli::array <System::Data::Objects::ObjectParameter ^> ^ parameters);
public System.Data.Objects.ObjectQuery<System.Data.Common.DbDataRecord> Select (string projection, params System.Data.Objects.ObjectParameter[] parameters);
member this.Select : string * System.Data.Objects.ObjectParameter[] -> System.Data.Objects.ObjectQuery<System.Data.Common.DbDataRecord>
Public Function Select (projection As String, ParamArray parameters As ObjectParameter()) As ObjectQuery(Of DbDataRecord)


String String String String

The list of selected properties that defines the projection.


Zero or more parameters that are used in this method.


A new ObjectQuery<T> instance of type DbDataRecord that is equivalent to the original instance with SELECT applied.



This example is based on the AdventureWorks Sales Model. The example creates a new ObjectQuery<T> whose results are data records that contain the ProductID fields of the results of this query.

int productID = 900;
using (AdventureWorksEntities context =
    new AdventureWorksEntities())
    string queryString = @"SELECT VALUE product FROM 
        AdventureWorksEntities.Products AS product
        WHERE product.ProductID > @productID";

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

    productQuery1.Parameters.Add(new ObjectParameter("productID", productID));

    ObjectQuery<DbDataRecord> productQuery2 =

    foreach (DbDataRecord result in productQuery2)
        Console.WriteLine("{0}", result["ProductID"]);
Dim productID = 900
Using context As New AdventureWorksEntities()
    Dim queryString As String = "SELECT VALUE product FROM AdventureWorksEntities.Products AS product" & _
            " WHERE product.ProductID > @productID"

    Dim productQuery1 As New ObjectQuery(Of Product)(queryString, context, MergeOption.NoTracking)
    productQuery1.Parameters.Add(New ObjectParameter("productID", productID))

    Dim productQuery2 As ObjectQuery(Of DbDataRecord) = productQuery1.Select("it.ProductID")

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


Select applies the projection specified by the projection parameter. The ObjectQuery<T> returned by the Select method is always a row type of DbDataRecord. Use the SelectValue method to return values that are simple types, entity types, or complex types. For more information, see LINQ to Entities.

When a navigation property is included in the projection, the query results include a collection of nested DbDataRecord objects. For more information, see How to: Navigate Relationships Using Navigation Properties.

Applies to

See also