更新 : 2007 年 11 月
EntityDataSource コントロールの Include プロパティを使用して、コンマ区切りのクエリ パスのリストを指定すると、明確に照会されたオブジェクトと共に返されるオブジェクトを定義できます。文字列内でコンマで区切られた各値は、EntityDataSource コントロールのデータ ソースである ObjectQuery<T> の Include メソッドの別個の呼び出しとして、変更されずに渡されます。
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");