You can use the Attach
or Detach
methods of the ObjectContext
to attach or detach objects. It should be noted that Attach
will attach the entire object graph. The method cannot determine which objects are new and which already exist in the ObjectContext
. Note that when you execute a query on the ObjectContext
, the objects that are returned as a result of the query are attached in the ObjectContext
. You can attach an object to the ObjectContext
by calling any of the following methods on the ObjectContext:
Attach
AddObject
AttachTo
ApplyPropertyChanges
But what does Attach
and Detach
mean here? You use Attach
to attach an object to the context. You should use Attach
when the entity already exists in the database want the context to know about it without doing a query to locate the entity. When you attach an entity to the ObjectContext
using the Attach
method, it sets the EntityState
of the object being attached to Unchanged...