EntityCollection<TEntity>.Attach Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
Attach(IEnumerable<TEntity>) |
Defines relationships between an object and a collection of related objects in an object context. |
Attach(TEntity) |
Defines a relationship between two attached objects in an object context. |
Attach(IEnumerable<TEntity>)
Defines relationships between an object and a collection of related objects in an object context.
public void Attach (System.Collections.Generic.IEnumerable<TEntity> entities);
override this.Attach : seq<'Entity (requires 'Entity : null)> -> unit
Public Sub Attach (entities As IEnumerable(Of TEntity))
Parameters
- entities
- IEnumerable<TEntity>
Collection of objects in the object context that are related to the source object.
Exceptions
entities collection is null.
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.
Remarks
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.
Applies to
Attach(TEntity)
Defines a relationship between two attached objects in an object context.
public void Attach (TEntity entity);
override this.Attach : 'Entity -> unit
Public Sub Attach (entity As TEntity)
Parameters
- entity
- TEntity
The object being attached.
Exceptions
When the entity is null.
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.
Applies to
Entity Framework