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)

abstract AutoGenerateWhereClause : bool with get, set 
override AutoGenerateWhereClause : bool with get, set
<asp:EntityDataSource AutoGenerateWhereClause="True|False" />

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.5.2, 4.5.1, 4.5, 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft