Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
LoadProperty(TEntity) Method (TEntity, Expression(Func(TEntity, Object)), MergeOption)

ObjectContext.LoadProperty<TEntity> Method (TEntity, Expression<Func<TEntity, Object>>, MergeOption)

.NET Framework 4.6 and 4.5

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

Namespace:  System.Data.Objects
Assembly:  System.Data.Entity (in System.Data.Entity.dll)

public void LoadProperty<TEntity>(
	TEntity entity,
	Expression<Func<TEntity, Object>> selector,
	MergeOption mergeOption

Type Parameters



Type: TEntity

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

Type: System.Linq.Expressions.Expression<Func<TEntity, Object>>

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

Type: System.Data.Objects.MergeOption

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


selector does not supply a valid input parameter.


selector is null.


The entity is in a Detached, [F:System.Data.EntityState.Added,] or Deleted state,


The entity is attached to another instance of ObjectContext.

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

.NET Framework

Supported in: 4.6, 4.5, 4

.NET Framework Client Profile

Supported in: 4
© 2015 Microsoft