Share via


DbContext.AttachRange Method

Definition

Overloads

AttachRange(Object[])

Begins tracking the given entities and entries reachable from the given entities using the Unchanged state by default, but see below for cases when a different state will be used.

AttachRange(IEnumerable<Object>)

Begins tracking the given entities and entries reachable from the given entities using the Unchanged state by default, but see below for cases when a different state will be used.

AttachRange(Object[])

Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs

Begins tracking the given entities and entries reachable from the given entities using the Unchanged state by default, but see below for cases when a different state will be used.

public virtual void AttachRange (params object[] entities);
abstract member AttachRange : obj[] -> unit
override this.AttachRange : obj[] -> unit
Public Overridable Sub AttachRange (ParamArray entities As Object())

Parameters

entities
Object[]

The entities to attach.

Remarks

Generally, no database interaction will be performed until SaveChanges() is called.

A recursive search of the navigation properties will be performed to find reachable entities that are not already being tracked by the context. All entities found will be tracked by the context.

For entity types with generated keys if an entity has its primary key value set then it will be tracked in the Unchanged state. If the primary key value is not set then it will be tracked in the Added state. This helps ensure only new entities will be inserted. An entity is considered to have its primary key value set if the primary key property is set to anything other than the CLR default for the property type.

For entity types without generated keys, the state set is always Unchanged.

Use State to set the state of only a single entity.

See EF Core change tracking and Using AddRange, UpdateRange, AttachRange, and RemoveRange for more information and examples.

Applies to

AttachRange(IEnumerable<Object>)

Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs

Begins tracking the given entities and entries reachable from the given entities using the Unchanged state by default, but see below for cases when a different state will be used.

public virtual void AttachRange (System.Collections.Generic.IEnumerable<object> entities);
abstract member AttachRange : seq<obj> -> unit
override this.AttachRange : seq<obj> -> unit
Public Overridable Sub AttachRange (entities As IEnumerable(Of Object))

Parameters

entities
IEnumerable<Object>

The entities to attach.

Remarks

Generally, no database interaction will be performed until SaveChanges() is called.

A recursive search of the navigation properties will be performed to find reachable entities that are not already being tracked by the context. All entities found will be tracked by the context.

For entity types with generated keys if an entity has its primary key value set then it will be tracked in the Unchanged state. If the primary key value is not set then it will be tracked in the Added state. This helps ensure only new entities will be inserted. An entity is considered to have its primary key value set if the primary key property is set to anything other than the CLR default for the property type.

For entity types without generated keys, the state set is always Unchanged.

Use State to set the state of only a single entity.

See EF Core change tracking and Using AddRange, UpdateRange, AttachRange, and RemoveRange for more information and examples.

Applies to