Table<TEntity>::AttachAll<TSubEntity> Method (IEnumerable<TSubEntity>, Boolean)
Attaches all entities of a collection to the DataContext in either a modified or unmodified state.
Assembly: System.Data.Linq (in System.Data.Linq.dll)
public: generic<typename TSubEntity> where TSubEntity : TEntity void AttachAll( IEnumerable<TSubEntity>^ entities, bool asModified )
Type Parameters
- TSubEntity
The type of entities to attach.
Parameters
- entities
- Type: System.Collections.Generic::IEnumerable<TSubEntity>
The collection of entities.
- asModified
- Type: System::Boolean
true if the object has a timestamp or RowVersion member, false if original values are being used for the optimistic concurrency check.
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.
The following example shows a scenario in which Customer A has canceled all orders and Customer B has taken ownership of them. You can attach all orders of Customer A at the same time.
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.