Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Defining Query Paths (EntityDataSource)

Updated: July 2008

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).

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");

Date

History

Reason

July 2008

Added topic.

SP1 feature change.

Community Additions

ADD
Show:
© 2015 Microsoft