Custom Command Text (EntityDataSource)

Updated: July 2008

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

When you assign CommandText to the EntityDataSource control, you can no longer update, insert, or delete through the control. In this case, the methods CanDelete, CanInsert, and CanUpdate of the related EntityDataSourceView control all return false.

The following example uses an Entity SQL command supplied to the CommandText property to return a collection of entities.

<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="ProductIDMin" Type="Int32"/>
            <asp:ControlParameter Name="OrderIDMax" 
                    ControlID="ProductIDMax" Type="Int32" />




July 2008

Added topic.

SP1 feature change.