Export (0) Print
Expand All

EntityDataSource.AutoGenerateWhereClause Property

Gets or sets a value that indicates whether the EntityDataSource control dynamically creates a WHERE clause based on values defined in the WhereParameters collection.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web.Entity (in System.Web.Entity.dll)

public bool AutoGenerateWhereClause { get; set; }

Property Value

Type: System.Boolean
true if the EntityDataSource control creates the WHERE clause; otherwise, false. The default value is false.

Implements

IDynamicDataSource.AutoGenerateWhereClause

ExceptionCondition
InvalidOperationException

When the AutoGenerateWhereClause property is set to true and the Where property is not null.

To filter query results by equating an entity type property to an expression, you can use the AutoGenerateWhereClause property. When the AutoGenerateWhereClause property of the EntityDataSource control is set to true, the control automatically generates a WHERE clause from the parameters in the ParameterCollection of the WhereParameters property. The Name property of each parameter has to match an entity type property name that is included in the query results. If you set the AutoGenerateWhereClause property to true, you should not explicitly assign a WHERE clause to the Where property.

Example

In the following example the AutoGenerateWhereClause property is set to true. Therefore, the Name of the property has to match an entity type property name that is included in the query results. The query selects the SalesOrderID and TotalDue properties of the SalesOrderHeader entity type. The automatically generated WHERE clause will filter the query results by comparing the TotalDue value to a value selected in the TotalDueList list box control.

<asp:EntityDataSource ID="SalesOrderHeaderWithAutoParam" runat="server" 
   ConnectionString="name=AdventureWorksEntities" 
   DefaultContainerName="AdventureWorksEntities" 
   EntitySetName="SalesOrderHeaders" 
   Select="it.SalesOrderID, it.TotalDue"
    AutoGenerateWhereClause="True">
    <WhereParameters>
        <asp:ControlParameter ControlID="TotalDueList" 
           Name="TotalDue" PropertyName="SelectedValue" DbType="Decimal" />
    </WhereParameters>
</asp:EntityDataSource>

Example

By default, the AutoGenerateWhereClause property is set to false. This means that we have to supply the WHERE clause. In the following example, the WHERE clause is Where="it.TotalDue < @totalDueParam" and totalDueParam is the parameter name.

<asp:EntityDataSource ID="SalesOrderHeaderWithOutAutoParam" runat="server" 
   ConnectionString="name=AdventureWorksEntities" 
   DefaultContainerName="AdventureWorksEntities" 
   EntitySetName="SalesOrderHeaders" 
   Where="it.TotalDue < @totalDueParam" 
    Select="it.SalesOrderID, it.TotalDue">
    <WhereParameters>
        <asp:ControlParameter ControlID="TotalDueList" 
           Name="totalDueParam" PropertyName="SelectedValue" DbType="Decimal" />
    </WhereParameters>
</asp:EntityDataSource>

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5 SP1
Show:
© 2015 Microsoft