Επεξεργασία

Κοινή χρήση μέσω


EntityDataSource.CommandText Property

Definition

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

public:
 property System::String ^ CommandText { System::String ^ get(); void set(System::String ^ value); };
public string CommandText { get; set; }
member this.CommandText : string with get, set
Public Property CommandText As String

Property Value

A string value that is the Entity SQL query.

Examples

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>

Remarks

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.

Applies to