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 Entity Framework 所執行之的方法 ObjectQuery<T> 。 此查詢是由控制項所管制之資料的來源 EntityDataSource 。 Include屬性是在執行之前套用至的引數 ObjectQuery<T> 。
提供給屬性的字串 Include 使用的格式與傳遞給 Include 方法的字串相同 ObjectQuery<T> 。 如需如何使用查詢路徑自動載入相關物件的範例,請參閱 如何:使用查詢路徑來塑造結果。
當 Include 屬性用來指定查詢路徑時,相關實體的屬性只能用於唯讀資料系結。 如果相關物件未明確包含在查詢路徑中,屬性描述項仍然可用於資料系結,但屬性本身會傳回 null 值。 在此情況下,必須明確載入相關物件以顯示其值。 如需詳細資訊,請參閱 載入相關物件。