This method attaches all entities of a collection to the DataContext in either a modified or unmodified state. If attaching as modified, the entity must either declare a version member or must not participate in update conflict checking. If attaching as unmodified, the entity is assumed to represent the original value. After calling this method, the entity's fields can be modified with other information from the client before SubmitChanges is called. For more information, see Data Retrieval and CUD Operations in N-Tier Applications (LINQ to SQL).

When a new entity is attached, deferred loaders for any child collections (for example, EntitySet collections of entities from associated tables) are initialized. When SubmitChanges is called, members of the child collections are put into an Unmodified state. To update members of a child collection, you must explicitly call Attach and specify that entity.

The following example shows how you can update an Order object on a different DataContext instance. The example assumes that you have a connection to a database and have made a LINQ to SQL file for it (in this case, the Northwind sample database).

In the following example, an entity object to be attached has a foreign key relation with another object and is stored in the cache but not attached. When you call SubmitChanges, the ChangeProcessor adds an Insert operation for all the foreign key objects. This is a side-effect when an entity instance is re-used in a different DataContext instance. For this reason, LINQ to SQL does not support re-use of objects.