Share via


Loading Related POCO Entities

Because POCO entities do not have the same relationship requirements as objects that inherit from EntityObject, a slightly different process is required to load related objects. For general information about loading related objects, see Loading Related Objects and Loading Related Objects.

You can load objects that are related to POCO entities by using the following methods.

  • Explicit Loading
    Because the navigation properties of POCO entities are not required to return EntityCollection or EntityReference types, the explicit loading of related objects cannot be performed by using the Load method that these classes implement. Instead, you must explicitly load related objects by using the LoadProperty method of the ObjectContext class. The following example loads the related LineItems for an Order by calling the LoadProperty method with a supplied lambda expression that selects all items.

    ' 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);
    

    For more information, see How to: Explicitly Load POCO Entities.

  • Eager Loading
    You can specify query paths to return related POCO entities. Use the Include method to eagerly return related objects just like with tool-generated entity types. For more information see, How to: Use Query Paths to Shape Results.

See Also

Concepts

Working with POCO Entities