加载相关 POCO 实体(实体框架)

因为 POCO 实体与自 EntityObject 继承的对象并不具有相同的关系要求,所以加载相关对象所需的过程将略有不同。 有关加载相关对象的一般信息,请参见加载相关对象(实体框架)加载相关对象(实体框架)

可以通过以下方法加载与 POCO 实体相关的对象。

  • 显式加载
    因为返回 EntityCollectionEntityReference 类型并不要求 POCO 实体的导航属性,所以,通过使用这些类实现的 Load 方法无法执行相关对象的显式加载。 而是必须使用 ObjectContext 类的 LoadProperty 方法显式加载相关对象。 以下示例通过使用所提供的选择所有项的 lambda 表达式调用 LoadProperty 方法,以加载 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);
    

    有关更多信息,请参见如何:显式加载 POCO 实体(实体框架)

另请参见

概念

使用 POCO 实体(实体框架)