EntityCollection<TEntity>.Attach Method

 

Attaches an entity to the EntityCollection.

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

NameDescription
System_CAPS_pubmethodAttach(TEntity)

Defines a relationship between two attached objects in an object context.

System_CAPS_pubmethodAttach(IEnumerable<TEntity>)

Defines relationships between an object and a collection of related objects in an object context.


EntityCollection<TEntity>.Attach Method (TEntity)

Defines a relationship between two attached objects in an object context.

public void Attach(
	TEntity entity
)

Parameters

entity
Type: TEntity

The object being attached.

Exception Condition
ArgumentNullException

When the entity is null.

InvalidOperationException

When the entity cannot be related to the source object. This can occur when the association in the conceptual schema does not support a relationship between the two types.-or-When either object is null or is not in an Unchanged or Modified state.


EntityCollection<TEntity>.Attach Method (IEnumerable<TEntity>)

Defines relationships between an object and a collection of related objects in an object context.

public void Attach(
	IEnumerable<TEntity> entities
)

Parameters

entities
Type: System.Collections.Generic.IEnumerable<TEntity>

Collection of objects in the object context that are related to the source object.

Exception Condition
ArgumentNullException

entities collection is null.

InvalidOperationException

The source object or an object in the entities collection is null or is not in an Unchanged or Modified state.-or-The relationship cannot be defined based on the EDM metadata. This can occur when the association in the conceptual schema does not support a relationship between the two types.

Loads related entities into the local collection. If the collection is already filled or partially filled, merges existing entities with the given entities. The given entities are not assumed to be the complete set of related entities. Owner and all entities passed in must be in Unchanged or Modified state. We allow deleted elements only when the state manager is already tracking the relationship instance.