Attaches an object or object graph to the object context when the object has an entity key.
Assembly: System.Data.Entity (in System.Data.Entity.dll)
Call 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 Attaching Objects (Entity Framework).
is used to attach an object or the top-level object in an object graph.
This method calls the AttachTo method.
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 example in this topic is based on the Adventure Works Sales Model. In this example, two objects are attached and then the relationship is defined.
Private Shared Sub AttachRelatedObjects(ByVal currentContext As ObjectContext, ByVal detachedOrder As SalesOrderHeader, ByVal detachedItems As List(Of SalesOrderDetail)) ' Attach the root detachedOrder object to the supplied context. currentContext.Attach(detachedOrder) ' Attach each detachedItem to the context, and define each relationship ' by attaching the attached SalesOrderDetail object to the EntityCollection on ' the SalesOrderDetail navigation property of the now attached detachedOrder. For Each item As SalesOrderDetail In detachedItems currentContext.Attach(item) detachedOrder.SalesOrderDetails.Attach(item) Next End Sub
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.