EntityDataSource.Include 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置指定要包含在查询结果中的相关对象的表达式。
public:
property System::String ^ Include { System::String ^ get(); void set(System::String ^ value); };
public string Include { get; set; }
member this.Include : string with get, set
Public Property Include As String
属性值
要在查询结果中返回的以逗号分隔的查询路径列表。
示例
下面的 XML 标记定义一个查询路径,该查询路径返回 SalesOrderHeader
与返回的对象相关的对象 Contact
。 对于每个 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 示例与下面命名的示例相同 ObjectQuery<T> customers
:
ObjectQuery<Contact> customers =
context.Contact
.Where("it.ContactID = @ContactID",
new ObjectParameter("ContactID", customerId))
.Include("SalesOrderHeader.SalesOrderDetail")
.Include("SalesOrderHeader.Address");
注解
Include控件的属性 EntityDataSource 指定以逗号分隔的查询路径列表,该列表定义与专门查询的对象一起返回的对象。 字符串中的每个逗号分隔值都将传递,而不进行修改,作为对 Include 实体框架执行的方法的单独调用 ObjectQuery<T> 。 此查询是控件控制的数据源 EntityDataSource 。 Include属性是在执行之前应用于的参数 ObjectQuery<T> 。
提供给属性的字符串 Include 使用的格式与传递到的方法的字符串相同 Include ObjectQuery<T> 。 有关如何使用查询路径自动加载相关对象的示例,请参阅 如何:使用查询路径来确定结果的形状。
如果 Include 使用属性指定查询路径,则相关实体的属性仅可用于只读数据绑定。 如果未在查询路径中显式包含相关对象,则属性描述符仍可用于数据绑定,但属性本身返回 null 值。 在这种情况下,必须显式加载相关对象以显示其值。 有关详细信息,请参阅 加载相关对象。