Export (0) Print
Expand All

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

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">
        <asp:ControlParameter ControlID="customerId" Name="ContactID" 
            PropertyName="Text" />

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

ObjectQuery<Contact> contacts =
       .Where("it.ContactID = @ContactID",
         new ObjectParameter("ContactID", customerId))

Community Additions

© 2014 Microsoft