Redigera

Dela via


ObjectContext.LoadProperty Method

Definition

Explicitly loads a related object when you are using POCO custom data classes.

Overloads

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)

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

Explicitly loads an object that is related to the supplied object by the specified LINQ query and by using the default merge option.

Remarks

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. This 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. 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)

Parameters

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.

Exceptions

The entity is in a Detached, Added or Deleted state,

-or-

The entity is attached to another instance of ObjectContext.

Remarks

The LoadProperty method must be called to achieve explicit loading when you are using POCO custom data classes.

After calling LoadProperty, the related object can be accessed through the navigation properties of the source entity.

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. This 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. 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>.

When the LoadProperty method is called, objects are loaded into the ObjectContext by using the default MergeOption value of AppendOnly.

Applies to

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)

Parameters

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

The MergeOption value to use when you load the related objects.

Exceptions

The entity is in a Detached, Added or Deleted state,

-or-

The entity is attached to another instance of ObjectContext.

Remarks

The LoadProperty method must be called to achieve explicit loading when you are using POCO custom data classes.

After calling LoadProperty, the related object can be accessed through the navigation properties of the source entity.

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. This 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. 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>.

Applies to

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

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)

Type Parameters

TEntity

The type of the supplied object.

Parameters

entity
TEntity

The source object for which related objects are to be loaded.

selector
Expression<Func<TEntity,Object>>

A LINQ expression that defines the related objects to be loaded.

mergeOption
MergeOption

The MergeOption value to use when you load the related objects.

Exceptions

selector does not supply a valid input parameter.

selector is null.

The entity is in a Detached, Added or Deleted state,

-or-

The entity is attached to another instance of ObjectContext.

Remarks

The LoadProperty method must be called to achieve explicit loading when you are using POCO custom data classes.

After calling LoadProperty, the related object can be accessed through the navigation properties of the source entity.

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. An exception will occur if other forms of the LINQ expression are used.

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. This 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. 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>.

Applies to

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

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

Type Parameters

TEntity

The type of the supplied object.

Parameters

entity
TEntity

The source object for which related objects are to be loaded.

selector
Expression<Func<TEntity,Object>>

A LINQ expression that defines the related objects to be loaded.

Exceptions

selector does not supply a valid input parameter.

selector is null.

The entity is in a Detached, Added or Deleted state,

-or-

The entity is attached to another instance of ObjectContext.

Remarks

The LoadProperty method must be called to achieve explicit loading when you are using POCO custom data classes.

After calling LoadProperty, the related object can be accessed through the navigation properties of the source entity.

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. An exception will occur if other forms of the LINQ expression are used.

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. This 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. 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>.

Applies to