Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Attach Method

DbSet<TEntity>::Attach Method

Entity Framework 5.0

Attaches the given entity to the context in the Unchanged

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

public:
virtual TEntity Attach(
	TEntity entity
) sealed

Parameters

entity
Type: TEntity

The entity to attach.

Return Value

Type: TEntity
Returns [{0}].

Implements

IDbSet<TEntity>::Attach(TEntity)

Attach is used to repopulate a context with an entity that is known to already exist in the database. SaveChanges will therefore not attempt to insert an attached entity into the database because it is assumed to already be there. Entities that are already in the context in some other state will have their state set to unchanged. Attach is a no-op if the entity is already in the context in the unchanged state.

Show:
© 2015 Microsoft