Table<TEntity>.Attach Method (TEntity)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Attaches a disconnected or "detached" entity to a new DataContext when original values are required for optimistic concurrency checks.

Namespace:  System.Data.Linq
Assembly:  System.Data.Linq (in System.Data.Linq.dll)

Syntax

'Declaration
Public Sub Attach ( _
    entity As TEntity _
)
public void Attach(
    TEntity entity
)

Parameters

  • entity
    Type: TEntity
    The original values of the entity to be attached.

Implements

ITable<TEntity>.Attach(TEntity)

Remarks

Use the Attach methods with entities that have been created in one DataContext, serialized to a client, and then deserialized back to perform an update or delete operation. Because the new DataContext has no way of tracking what the original values were for a disconnected entity, the client is responsible for supplying those values. In this version of Attach, the entity is assumed to be in its original value state. After calling this method, you can then update its fields, for example with additional data sent from the client.

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.

Do not try to Attach an entity that has not been detached through serialization. Entities that have not been serialized still maintain associations with deferred loaders that can cause unexpected results if the entity becomes tracked by a second data context.

Version Information

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.