.Attach Method (IEntityWithKey)
.NET Framework (current version)
Attaches an object or object graph to the object context when the object has an entity key.
System.Data.Entity (in System.Data.Entity.dll)
member Attach :
entity:IEntityWithKey -> unit
Attach on the ObjectContext to attach the object to the object context. Do this when the object already exists in the data source but is currently not attached to the context. For more information, see Customizing Objects. Attach is used to attach an object or the top-level object in an object graph.
The object being attached must implement
IEntityWithKey to expose an EntityKey. All generated entity classes implement IEntityWithKey.
When you attach related objects, you must also call
Attach on the EntityReference or the <'TEntity> EntityCollection to define the relationship. <'TEntity>
This method calls the
The following considerations apply when attaching objects:
If the object being attached has related objects, those objects will also be attached to the object context.
Objects are added to the object context in an unchanged state.
The object that is passed to the
Attach method must have a valid value. If the object does not have a valid EntityKey value, use the EntityKey AttachTo method to specify the name of the entity set.
The example in this topic is based on the
AdventureWorks Sales Model. In this example, two objects are attached and then the relationship is defined.
No code example is currently available or this language may not be supported.
Available since 3.5 Return to top