Defining Query Paths (EntityDataSource)

You can define which objects return along with the specifically queried object by using the Include property of the EntityDataSource control to specify a comma-separated list of query paths. Each comma-separated value in the string is passed, without modification, as a separate call to the Include method of the ObjectQuery<T> that is the data source for the EntityDataSource control.

The string supplied to the Include property uses the same format as the string passed to the Include method of ObjectQuery<T>. For examples of how to use query paths to automatically load related objects, see How to: Use Query Paths to Shape Results (Entity Framework).

Example

The following XML markup defines a query path that returns SalesOrderHeader objects that are related to the returned Contact object. With each SalesOrderHeader, the related SalesOrderDetail and Address objects are also returned.

<asp:EntityDataSource ID="ContactDataSource" runat="server" 
    AutoGenerateWhereClause="True" ConnectionString="name=AdventureWorksEntities" 
    DefaultContainerName="AdventureWorksEntities" EnableDelete="True" 
    EnableInsert="True" EnableUpdate="True" EntitySetName="Contact" 
    Include="SalesOrderHeader.SalesOrderDetail, SalesOrderHeader.Address">
    <WhereParameters>
        <asp:ControlParameter ControlID="customerId" Name="ContactID" 
            PropertyName="Text" />
    </WhereParameters>
</asp:EntityDataSource>

The previous XML example is the same as the following ObjectQuery<T> named contacts:

ObjectQuery<Contact> contacts = 
      context.Contact
       .Where("it.ContactID = @ContactID",
         new ObjectParameter("ContactID", customerId))
        .Include("SalesOrderHeader.SalesOrderDetail")
        .Include("SalesOrderHeader.Address");

See Also

Concepts

Configuring the EntityDataSource Control

Filtering Data (EntityDataSource)

EntityDataSource Designer

Other Resources

Shaping Query Results (Entity Framework)

Change History

Date

History

Reason

July 2008

Added topic.

SP1 feature change.