ObjectContext.LoadProperty 方法

定义

在使用 POCO 自定义数据类时显式加载相关对象。Explicitly loads a related object when you are using POCO custom data classes.

重载

LoadProperty(Object, String)

通过指定的导航属性并使用默认合并选项,显式加载与提供的对象相关的对象。Explicitly loads an object related to the supplied object by the specified navigation property and using the default merge option.

LoadProperty(Object, String, MergeOption)

通过指定的导航属性并使用指定的合并选项,显式加载与提供的对象相关的对象。Explicitly loads an object that is related to the supplied object by the specified navigation property and using the specified merge option.

LoadProperty<TEntity>(TEntity, Expression<Func<TEntity,Object>>, MergeOption)

通过指定的 LINQ 查询并使用指定的合并选项,显式加载与提供的对象相关的对象。Explicitly loads an object that is related to the supplied object by the specified LINQ query and by using the specified merge option.

LoadProperty<TEntity>(TEntity, Expression<Func<TEntity,Object>>)

通过指定的 LINQ 查询并使用默认合并选项,显式加载与提供的对象相关的对象。Explicitly loads an object that is related to the supplied object by the specified LINQ query and by using the default merge option.

注解

使用 POCO 自定义数据类时,无法显式加载相关对象,如实体数据模型工具生成的实体类型的实例。When using POCO custom data classes, related objects cannot be explicitly loaded like instances of entity types that are generated by the Entity Data Model tools. 这是因为 EntityCollection<TEntity> EntityReference<TEntity>Load 在上调用时,这些工具会生成返回或相关对象的导航属性 RelatedEndThis is because the tools generate the navigation properties that return an EntityCollection<TEntity> or EntityReference<TEntity> of related objects when Load is called on a RelatedEnd. 通过在 LazyLoadingEnabled true 属性返回的实例上将属性设置为 ObjectContextOptions ObjectContext.ContextOptions ,或对使用方法预先加载 Include ObjectQuery<T> ,仍可以使用延迟加载来加载 POCO 实体。POCO entities can still be loaded by using lazy loading by setting the LazyLoadingEnabled property to true on the instance of ObjectContextOptions that is returned by the ObjectContext.ContextOptions property, or by using eager loading with the Include method on the ObjectQuery<T>.

LoadProperty(Object, String)

通过指定的导航属性并使用默认合并选项,显式加载与提供的对象相关的对象。Explicitly loads an object related to the supplied object by the specified navigation property and using the default merge option.

public:
 void LoadProperty(System::Object ^ entity, System::String ^ navigationProperty);
public void LoadProperty (object entity, string navigationProperty);
member this.LoadProperty : obj * string -> unit
Public Sub LoadProperty (entity As Object, navigationProperty As String)

参数

entity
Object

要为其加载相关对象的实体。The entity for which related objects are to be loaded.

navigationProperty
String

可返回要加载的相关对象的导航属性的名称。The name of the navigation property that returns the related objects to be loaded.

例外

entity 处于 DetachedAddedDeleted 状态。The entity is in a Detached, Added or Deleted state,

- 或 --or-

entity 附加到 ObjectContext 的另一个实例。The entity is attached to another instance of ObjectContext.

注解

LoadProperty使用 POCO 自定义数据类时,必须调用方法以实现显式加载。The LoadProperty method must be called to achieve explicit loading when you are using POCO custom data classes.

调用后 LoadProperty ,可以通过源实体的导航属性访问相关的对象。After calling LoadProperty, the related object can be accessed through the navigation properties of the source entity.

使用 POCO 自定义数据类时,无法显式加载相关对象,如实体数据模型工具生成的实体类型的实例。When using POCO custom data classes, related objects cannot be explicitly loaded like instances of entity types that are generated by the Entity Data Model tools. 这是因为 EntityCollection<TEntity> EntityReference<TEntity>Load 在上调用时,这些工具会生成返回或相关对象的导航属性 RelatedEndThis is because the tools generate the navigation properties that return an EntityCollection<TEntity> or EntityReference<TEntity> of related objects when Load is called on a RelatedEnd. 通过在 LazyLoadingEnabled true 属性返回的实例上将属性设置为 ObjectContextOptions ObjectContext.ContextOptions ,或对使用方法预先加载 Include ObjectQuery<T> ,仍可以使用延迟加载来加载 POCO 实体。POCO entities can still be loaded by using lazy loading by setting the LazyLoadingEnabled property to true on the instance of ObjectContextOptions that is returned by the ObjectContext.ContextOptions property, or by using eager loading with the Include method on the ObjectQuery<T>.

LoadProperty调用方法时, ObjectContext 通过使用的默认值将对象加载到中 MergeOption AppendOnlyWhen the LoadProperty method is called, objects are loaded into the ObjectContext by using the default MergeOption value of AppendOnly.

适用于

LoadProperty(Object, String, MergeOption)

通过指定的导航属性并使用指定的合并选项,显式加载与提供的对象相关的对象。Explicitly loads an object that is related to the supplied object by the specified navigation property and using the specified merge option.

public:
 void LoadProperty(System::Object ^ entity, System::String ^ navigationProperty, System::Data::Objects::MergeOption mergeOption);
public void LoadProperty (object entity, string navigationProperty, System.Data.Objects.MergeOption mergeOption);
member this.LoadProperty : obj * string * System.Data.Objects.MergeOption -> unit
Public Sub LoadProperty (entity As Object, navigationProperty As String, mergeOption As MergeOption)

参数

entity
Object

要为其加载相关对象的实体。The entity for which related objects are to be loaded.

navigationProperty
String

可返回要加载的相关对象的导航属性的名称。The name of the navigation property that returns the related objects to be loaded.

mergeOption
MergeOption

在加载相关对象时要使用的 MergeOption 值。The MergeOption value to use when you load the related objects.

例外

entity 处于 DetachedAddedDeleted 状态。The entity is in a Detached, Added or Deleted state,

- 或 --or-

entity 附加到 ObjectContext 的另一个实例。The entity is attached to another instance of ObjectContext.

注解

LoadProperty使用 POCO 自定义数据类时,必须调用方法以实现显式加载。The LoadProperty method must be called to achieve explicit loading when you are using POCO custom data classes.

调用后 LoadProperty ,可以通过源实体的导航属性访问相关的对象。After calling LoadProperty, the related object can be accessed through the navigation properties of the source entity.

使用 POCO 自定义数据类时,无法显式加载相关对象,如实体数据模型工具生成的实体类型的实例。When using POCO custom data classes, related objects cannot be explicitly loaded like instances of entity types that are generated by the Entity Data Model tools. 这是因为 EntityCollection<TEntity> EntityReference<TEntity>Load 在上调用时,这些工具会生成返回或相关对象的导航属性 RelatedEndThis is because the tools generate the navigation properties that return an EntityCollection<TEntity> or EntityReference<TEntity> of related objects when Load is called on a RelatedEnd. 通过在 LazyLoadingEnabled true 属性返回的实例上将属性设置为 ObjectContextOptions ObjectContext.ContextOptions ,或对使用方法预先加载 Include ObjectQuery<T> ,仍可以使用延迟加载来加载 POCO 实体。POCO entities can still be loaded by using lazy loading by setting the LazyLoadingEnabled property to true on the instance of ObjectContextOptions that is returned by the ObjectContext.ContextOptions property, or by using eager loading with the Include method on the ObjectQuery<T>.

适用于

LoadProperty<TEntity>(TEntity, Expression<Func<TEntity,Object>>, MergeOption)

通过指定的 LINQ 查询并使用指定的合并选项,显式加载与提供的对象相关的对象。Explicitly loads an object that is related to the supplied object by the specified LINQ query and by using the specified merge option.

public:
generic <typename TEntity>
 void LoadProperty(TEntity entity, System::Linq::Expressions::Expression<Func<TEntity, System::Object ^> ^> ^ selector, System::Data::Objects::MergeOption mergeOption);
public void LoadProperty<TEntity> (TEntity entity, System.Linq.Expressions.Expression<Func<TEntity,object>> selector, System.Data.Objects.MergeOption mergeOption);
member this.LoadProperty : 'Entity * System.Linq.Expressions.Expression<Func<'Entity, obj>> * System.Data.Objects.MergeOption -> unit
Public Sub LoadProperty(Of TEntity) (entity As TEntity, selector As Expression(Of Func(Of TEntity, Object)), mergeOption As MergeOption)

类型参数

TEntity

提供的对象的类型。The type of the supplied object.

参数

entity
TEntity

要为其加载相关对象的源对象。The source object for which related objects are to be loaded.

selector
Expression<Func<TEntity,Object>>

定义要加载的相关对象的 LINQ 表达式。A LINQ expression that defines the related objects to be loaded.

mergeOption
MergeOption

在加载相关对象时要使用的 MergeOption 值。The MergeOption value to use when you load the related objects.

例外

selector 未提供有效的输入参数。selector does not supply a valid input parameter.

selector 为 null。selector is null.

entity 处于 DetachedAddedDeleted 状态。The entity is in a Detached, Added or Deleted state,

- 或 --or-

entity 附加到 ObjectContext 的另一个实例。The entity is attached to another instance of ObjectContext.

注解

LoadProperty使用 POCO 自定义数据类时,必须调用方法以实现显式加载。The LoadProperty method must be called to achieve explicit loading when you are using POCO custom data classes.

调用后 LoadProperty ,可以通过源实体的导航属性访问相关的对象。After calling LoadProperty, the related object can be accessed through the navigation properties of the source entity.

要加载的属性由 LINQ 表达式指定,该表达式必须是简单属性成员访问的形式,如 (entity) => entity.PropertyName PropertyName 是用于返回要加载的相关对象的导航属性。The property to load is specified by a LINQ expression, which must be in the form of a simple property member access, as in (entity) => entity.PropertyName where PropertyName is the navigation property that returns the related objects to be loaded. 如果使用其他形式的 LINQ 表达式,则会出现异常。An exception will occur if other forms of the LINQ expression are used.

使用 POCO 自定义数据类时,无法显式加载相关对象,如实体数据模型工具生成的实体类型的实例。When using POCO custom data classes, related objects cannot be explicitly loaded like instances of entity types that are generated by the Entity Data Model tools. 这是因为 EntityCollection<TEntity> EntityReference<TEntity>Load 在上调用时,这些工具会生成返回或相关对象的导航属性 RelatedEndThis is because the tools generate the navigation properties that return an EntityCollection<TEntity> or EntityReference<TEntity> of related objects when Load is called on a RelatedEnd. 通过在 LazyLoadingEnabled true 属性返回的实例上将属性设置为 ObjectContextOptions ObjectContext.ContextOptions ,或对使用方法预先加载 Include ObjectQuery<T> ,仍可以使用延迟加载来加载 POCO 实体。POCO entities can still be loaded by using lazy loading by setting the LazyLoadingEnabled property to true on the instance of ObjectContextOptions that is returned by the ObjectContext.ContextOptions property, or by using eager loading with the Include method on the ObjectQuery<T>.

适用于

LoadProperty<TEntity>(TEntity, Expression<Func<TEntity,Object>>)

通过指定的 LINQ 查询并使用默认合并选项,显式加载与提供的对象相关的对象。Explicitly loads an object that is related to the supplied object by the specified LINQ query and by using the default merge option.

public:
generic <typename TEntity>
 void LoadProperty(TEntity entity, System::Linq::Expressions::Expression<Func<TEntity, System::Object ^> ^> ^ selector);
public void LoadProperty<TEntity> (TEntity entity, System.Linq.Expressions.Expression<Func<TEntity,object>> selector);
member this.LoadProperty : 'Entity * System.Linq.Expressions.Expression<Func<'Entity, obj>> -> unit
Public Sub LoadProperty(Of TEntity) (entity As TEntity, selector As Expression(Of Func(Of TEntity, Object)))

类型参数

TEntity

提供的对象的类型。The type of the supplied object.

参数

entity
TEntity

要为其加载相关对象的源对象。The source object for which related objects are to be loaded.

selector
Expression<Func<TEntity,Object>>

定义要加载的相关对象的 LINQ 表达式。A LINQ expression that defines the related objects to be loaded.

例外

selector 未提供有效的输入参数。selector does not supply a valid input parameter.

selector 为 null。selector is null.

entity 处于 DetachedAddedDeleted 状态。The entity is in a Detached, Added or Deleted state,

- 或 --or-

entity 附加到 ObjectContext 的另一个实例。The entity is attached to another instance of ObjectContext.

注解

LoadProperty使用 POCO 自定义数据类时,必须调用方法以实现显式加载。The LoadProperty method must be called to achieve explicit loading when you are using POCO custom data classes.

调用后 LoadProperty ,可以通过源实体的导航属性访问相关的对象。After calling LoadProperty, the related object can be accessed through the navigation properties of the source entity.

要加载的属性由 LINQ 表达式指定,该表达式必须采用简单属性成员访问的形式,如中所示 (entity) => entity.PropertyName ,其中 PropertyName 是用于返回要加载的相关对象的导航属性。The property to load is specified by a LINQ expression, which must be in the form of a simple property member access, as in (entity) => entity.PropertyName, where PropertyName is the navigation property that returns the related objects to be loaded. 如果使用其他形式的 LINQ 表达式,则会出现异常。An exception will occur if other forms of the LINQ expression are used.

使用 POCO 自定义数据类时,无法显式加载相关对象,如实体数据模型工具生成的实体类型的实例。When using POCO custom data classes, related objects cannot be explicitly loaded like instances of entity types that are generated by the Entity Data Model tools. 这是因为 EntityCollection<TEntity> EntityReference<TEntity>Load 在上调用时,这些工具会生成返回或相关对象的导航属性 RelatedEndThis is because the tools generate the navigation properties that return an EntityCollection<TEntity> or EntityReference<TEntity> of related objects when Load is called on a RelatedEnd. 通过在 LazyLoadingEnabled true 属性返回的实例上将属性设置为 ObjectContextOptions ObjectContext.ContextOptions ,或对使用方法预先加载 Include ObjectQuery<T> ,仍可以使用延迟加载来加载 POCO 实体。POCO entities can still be loaded by using lazy loading by setting the LazyLoadingEnabled property to true on the instance of ObjectContextOptions that is returned by the ObjectContext.ContextOptions property, or by using eager loading with the Include method on the ObjectQuery<T>.

适用于