定义查询路径 (EntityDataSource)

更新:2007 年 11 月

通过使用 EntityDataSource 控件的 Include 属性来指定逗号分隔的查询路径列表,可以定义哪些对象与专门查询的对象一起返回。字符串中每个以逗号分隔的值都将被传递,而不会进行修改,作为对 ObjectQuery<T>Include 方法的单独调用,该查询是 EntityDataSource 控件的数据源。

提供给 Include 属性的字符串与传递给 ObjectQuery<T>Include 方法的字符串具有相同的格式。有关如何使用查询路径来自动加载相关对象的信息,请参见如何:使用查询路径形成结果 (Entity Framework)

示例

下面的 XML 标记定义一个查询路径,该路径返回与返回的 Contact 对象相关的 SalesOrderHeader 对象。对于每个 SalesOrderHeader,还将返回相关的 SalesOrderDetail 和 Address 对象。

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

上面的 XML 示例与下面的名为 contacts 的 ObjectQuery<T> 相同:

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

请参见

概念

配置 EntityDataSource 控件

筛选数据 (EntityDataSource)

EntityDataSource 设计器

其他资源

形成查询结果 (Entity Framework)