This documentation is archived and is not being maintained.

EntityDataSource.CommandText Property

Gets or sets an Entity SQL command that defines the query.

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

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

Property Value

Type: System.String
A string value that is the Entity SQL query.

The CommandText property of the EntityDataSource control enables you to specify a query that uses a custom Entity SQL expression. Like the SELECT statement, CommandText creates a projection of the original data that is not updatable.

When the CommandText property is assigned, update, insert, and delete functionalities are disabled. In this case, the methods CanDelete, CanInsert, and CanUpdate of the related EntityDataSourceView control all return false.

When the CommandText property is set, an exception is thrown when the ExecuteSelect method is called by a control that is data bound to an EntityDataSource control if the value of EnableInsert, EnableUpdate, or EnableDelete is set to true.

If the CommandText 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 example uses the supplied Entity SQL command to returns a collection of Product objects.

<asp:EntityDataSource ID="ProductDataSource" runat="server" 
    CommandText="SELECT value p FROM Products AS p
        WHERE p.ProductID
        BETWEEN @OrderIdMin AND @OrderIdMax"
    DefaultContainerName="AdventureWorksEntities" >
        <asp:ControlParameter Name="OrderIdMin" 
            ControlID="ProductIdMin" Type="Int32"/>
        <asp:ControlParameter Name="OrderIdMax" 
            ControlID="ProductIdMax" Type="Int32" />

The following example returns a projected series of columns:

    <asp:EntityDataSource ID="ProductDataSource" runat="server" 
        CommandText="SELECT p.ProductID, p.ProductName, p.UnitsOnOrder
              FROM Products AS p 
              WHERE p.ProductID BETWEEN @OrderIDMin AND @OrderIDMax" 
              ContextTypeName="AdventureWorksModel. AdventureWorksEntities">
            <asp:ControlParameter Name="OrderIDMin" 
                    ControlID="ProductIDMinTextBox" Type="Int32"/>
            <asp:ControlParameter Name="OrderIDMax" 
                    ControlID="ProductIDMaxTextBox" Type="Int32" />

.NET Framework

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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