Export (0) Print
Expand All

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.

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

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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

.NET Framework

Supported in: 3.5 SP1

Community Additions

ADD
Show:
© 2014 Microsoft