EntityDataSource.CommandText プロパティ

定義

クエリを定義する Entity SQL コマンドを取得または設定します。

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

プロパティ値

Entity SQL クエリである string 値。

次の例では、指定された Entity SQL コマンドを使用して Product オブジェクトのコレクションを返します。

<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>

次の例では、投影された一連の列を返します。

<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>

注釈

CommandTextコントロールの プロパティをEntityDataSource使用すると、カスタム Entity SQL 式を使用するクエリを指定できます。 SELECT ステートメントと同様に、 CommandText 更新できない元のデータのプロジェクションを作成します。

プロパティが CommandText 割り当てられると、更新、挿入、および削除の機能は無効になります。 この場合、関連するコントロールの CanDeleteメソッド 、CanInsert、および CanUpdate はすべて を返しますfalseEntityDataSourceView

プロパティがCommandText設定されている場合、、、または EnableDelete の値EnableUpdateEnableInsertが にtrue設定されている場合、コントロールにEntityDataSourceバインドされたデータであるコントロールによってメソッドが呼び出されるとExecuteSelect、例外がスローされます。

CommandTextがプロパティのプロジェクション ("SELECT p.ProductID, p. Name FROM AdventureWorksEntities.Products AS p"など) DbDataRecord を返すクエリに設定されている場合は、 が返されます。

適用対象