EntityCollection<TEntity>::Attach Method (IEnumerable<TEntity>^)
Defines relationships between an object and a collection of related objects in an object context.
Assembly: System.Data.Entity (in System.Data.Entity.dll)
| Exception | Condition |
|---|---|
| ArgumentNullException | entities collection is null. |
| InvalidOperationException |
The Attach method is used to define relationships between an object and a collection of related objects when both the source object and the collection of related objects already exist in the object context. To attach an object or an object graph where the relationships are already defined, call the Attach method on the ObjectContext. To create a new object that is related to the source object, call the Add method on the EntityCollection<TEntity>. For more information, see Attaching and Detaching Objects.
If the collection is already filled or partially filled, the M:System.Data.Objects.DataClasses.EntityCollection`1.Attach method merges existing entities with the given entities. The given entities are not assumed to be the complete set of related entities.
All entities passed in must be in the Unchanged or Modified state. Objects in the Deleted state are only allowed when the state manager is already tracking the relationship instance.
Available since 3.5