Custom Command Text (EntityDataSource)
Visual Studio 2010
Updated: July 2008
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.
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>
Community Additions
ADD
Show: