Export (0) Print
Expand All

EntityDataSource.Select Property

Gets or sets the projection that defines the properties to include in the query results.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web.Entity (in System.Web.Entity.dll)

public string Select { get; set; }
<asp:EntityDataSource Select="String" />

Property Value

Type: System.String
The parameters that are used for creating the ORDER BY clause.

ExceptionCondition
InvalidOperationException

When the Select property specifies a query projection and the value of EnableUpdate, EnableDelete, or EnableInsert is true.

The Select property of the EntityDataSource control contains a string that represents the SELECT statement of an Entity SQL query. This enables you to project a specified set of properties from the objects returned by the query.

This string is passed, without modification, to the ObjectQuery<T> that is executed by the Entity Framework. This query is the source of the data regulated by the EntityDataSource control. The string supplied to the Select property uses the same format as the string that is passed to the Select method of ObjectQuery<T>. For examples of how to use the SELECT clause to define a projection for a query, see How to: Execute a Query that Returns an Anonymous Type (Entity Framework).

Updates are not supported for projected data. This means that when you use the Select property to specify a projection, the bound data binding does not support updates.

When you define a projection with paging enabled, you must define the property by which to order the results. This means the when you set the Select property to defined a projection and have AutoPage set to true, you must also set the OrderBy property to define the order or set the AutoGenerateOrderByClause property to true and add an ORDER BY parameter to the OrderByParameters collection.

Select cannot be set if EnableUpdate, EnableDelete, or EnableInsert is enabled.

If the Select is set to a query that returns a projection of properties (for example, SELECT p.ProductID, p. Name FROM AdventureWorksEntities.Products AS p), a DbDataRecord will be returned.

The following XML markup uses the Select property to specify a projection with six of the properties of the Product type:

<asp:EntityDataSource ID="ProductDataSource" runat="server" 
    ConnectionString="name=AdventureWorksEntities" 
    DefaultContainerName="AdventureWorksEntities" 
    EntitySetName="Product" OrderBy="it.[ProductID]" 
    Select="it.[ProductID], it.[Name], it.[ListPrice], 
    it.[Size], it.[Style], it.[Weight]">
</asp:EntityDataSource> 

The previous XML example is the same as the following ObjectQuery<T> named products:

ObjectQuery<Product> products = context.Product
    .Select(it.[ProductID], it.[Name], it.[ListPrice], 
      it.[Size], it.[Style], it.[Weight])
    .OrderBy("it.[ProductID]");

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft