Export (0) Print
Expand All

EntityCollection<TEntity>::Load Method (MergeOption)

Loads related objects into the collection, using the specified merge option.

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

public:
virtual void Load(
	MergeOption mergeOption
) override

Parameters

mergeOption
Type: System.Data.Objects::MergeOption

Specifies how the objects in this collection should be merged with the objects that might have been returned from previous queries against the same ObjectContext.

Implements

IRelatedEnd::Load(MergeOption)

This method calls the ValidateLoad``1 method before loading the collection. See this method for a list of possible exceptions.

When objects in the collection are already loaded into the ObjectContext, the Load method enforces the MergeOption specified by the mergeOption parameter. For more information, see Managing the Object Context (Entity Framework).

To explicitly load related objects, you must call the Load method on the related end returned by the navigation property. For a one-to-many relationship, call the Load method on EntityCollection<TEntity>. For a one-to-one relationship, call the Load on EntityReference<TEntity>. This loads the related object data into the object context. You can enumerate through the collection of returned results using a foreach loop (For Each...Next in Visual Basic) and conditionally call the Load method on EntityReference<TEntity> and EntityCollection<TEntity> properties for each entity in the results.

The Load method loads related objects from the data source whether or not IsLoaded is true.

NoteNote

When you call the Load method during a foreach (C#) or For Each (Visual Basic) enumeration, Object Services tries to open a new data reader. This operation will fail unless you have enabled multiple active results sets by specifying multipleactiveresultsets=true in the connection string. You can also load the result of the query into a List<T> collection. This closes the data reader and enables you to enumerate over the collection to load referenced objects.

The EntityCollection<TEntity>::Load method is synchronized with the EntityReference<TEntity>::Load method.

This example is based on the Adventure Works Sales Model. To run the code in this example, you must have already added the AdventureWorks Sales Model to your project and configured your project to use the Entity Framework. To do this, complete the procedures in How to: Manually Configure an Entity Framework Project and How to: Manually Define an E*ntity Data Model (Entity Framework).

This example loads the related SalesOrderHeader objects for the Contact entity.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5 SP1

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft