Partilhar via


Custom Command Text (EntityDataSource)

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.

Examples

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"
    ConnectionString="name=AdventureWorksEntities" 
    DefaultContainerName="AdventureWorksEntities" >
    <CommandParameters>
        <asp:ControlParameter Name="OrderIdMin" 
            ControlID="ProductIdMin" Type="Int32"/>
        <asp:ControlParameter Name="OrderIdMax" 
            ControlID="ProductIdMax" Type="Int32" />
    </CommandParameters>
</asp:EntityDataSource>

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

See Also

Concepts

Data Projections (EntityDataSource)

Configuring the EntityDataSource Control

Filtering Data (EntityDataSource)

EntityDataSource Designer

Other Resources

Object Queries (Entity Framework)

Change History

Date

History

Reason

July 2008

Added topic.

SP1 feature change.