カスタム コマンド テキスト (EntityDataSource)

更新 : 2007 年 11 月

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

EntityDataSource コントロールに CommandText を割り当てると、コントロールを使用して更新、挿入、または削除を行うことはできなくなります。この場合、関連する EntityDataSourceView コントロールの CanDeleteCanInsert、および CanUpdate の各メソッドは、すべて false を返します。

次の例は、CommandText プロパティに指定された Entity SQL コマンドを使用して、エンティティのコレクションを返します。

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

参照

概念

データのプロジェクション (EntityDataSource)

EntityDataSource コントロールの構成

データのフィルタ処理 (EntityDataSource)

EntityDataSource デザイナ

その他の技術情報

オブジェクト クエリ (Entity Framework)