Share via


載入相關的 POCO 實體 (Entity Framework)

因為 POCO 實體沒有與繼承自 EntityObject 的物件有相同的關聯性需求,因此載入相關物件所需的程序稍有不同。 如需載入相關物件的一般資訊,請參閱載入相關的物件 (Entity Framework)載入相關的物件 (Entity Framework)

您可以使用下列方法,載入與 POCO 實體相關的物件。

  • 明確式載入
    因為傳回 EntityCollectionEntityReference 型別不需要 POCO 實體的導覽屬性,因此相關物件的明確式載入無法使用這些類別所實作的 Load 方法來執行。 相反地,您必須使用 ObjectContext 類別的 LoadProperty 方法,明確載入相關的物件。 下列範例會透過呼叫 LoadProperty 方法,以及所提供之選取全部項目的 Lambda 運算式,載入 Order 的相關 LineItems

    ' Because LazyLoadingEnabled is set to false, 
    ' we need to explicitly load the related line items for the order. 
    context.LoadProperty(order, Function(o) o.LineItems)
    
    // Because LazyLoadingEnabled is set to false,
    // we need to explicitly load the related line items for the order.
    context.LoadProperty(order, o => o.LineItems);
    

    如需詳細資訊,請參閱 HOW TO:明確載入 POCO 實體 (Entity Framework)

另請參閱

概念

使用 POCO 實體 (Entity Framework)