Delen via


EntityEntry.State Property

Definition

Gets or sets that state that this entity is being tracked in.

public virtual Microsoft.EntityFrameworkCore.EntityState State { get; set; }
member this.State : Microsoft.EntityFrameworkCore.EntityState with get, set
Public Overridable Property State As EntityState

Property Value

Remarks

This method sets only the state of the single entity represented by this entry. It does not change the state of other entities reachable from this one. However, this may cause cascading actions on other entities when setting the state to Deleted or Detached. This can be changed by changing CascadeDeleteTiming.

When setting the state, the entity will always end up in the specified state. For example, if you change the state to Deleted the entity will be marked for deletion regardless of its current state. This is different than calling Remove(TEntity) where the entity will be disconnected (rather than marked for deletion) if it is in the Added state.

See Accessing tracked entities in EF Core for more information and examples.

Applies to