DbContext.Update Method

Definition

Overloads

Update(Object)

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

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 Modified state. If the primary key value is not set then it will be tracked in the Added state. This helps ensure new entities will be inserted, while existing entities will be updated. 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 Modified.

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

Update<TEntity>(TEntity)

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

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 Modified state. If the primary key value is not set then it will be tracked in the Added state. This helps ensure new entities will be inserted, while existing entities will be updated. 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 Modified.

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

Update(Object)

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

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 Modified state. If the primary key value is not set then it will be tracked in the Added state. This helps ensure new entities will be inserted, while existing entities will be updated. 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 Modified.

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

public virtual Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry Update (object entity);
abstract member Update : obj -> Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry
override this.Update : obj -> Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry
Public Overridable Function Update (entity As Object) As EntityEntry

Parameters

entity
Object

The entity to update.

Returns

Update<TEntity>(TEntity)

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

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 Modified state. If the primary key value is not set then it will be tracked in the Added state. This helps ensure new entities will be inserted, while existing entities will be updated. 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 Modified.

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

public virtual Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<TEntity> Update<TEntity> (TEntity entity) where TEntity : class;
abstract member Update : 'Entity -> Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<'Entity (requires 'Entity : null)> (requires 'Entity : null)
override this.Update : 'Entity -> Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<'Entity (requires 'Entity : null)> (requires 'Entity : null)
Public Overridable Function Update(Of TEntity As Class) (entity As TEntity) As EntityEntry(Of TEntity)

Type Parameters

TEntity

The type of the entity.

Parameters

entity
TEntity

The entity to update.

Returns

Applies to