Class EntityEntry
- Namespace
- Microsoft.EntityFrameworkCore.ChangeTracking
- Assembly
- Microsoft.EntityFrameworkCore.dll
Provides access to change tracking information and operations for a given entity.
public class EntityEntry : IInfrastructure<InternalEntityEntry>
- Inheritance
-
EntityEntry
- Implements
- Derived
- Inherited Members
- Extension Methods
Remarks
Instances of this class are returned from methods when using the ChangeTracker API and it is not designed to be directly constructed in your application code.
See Accessing tracked entities in EF Core for more information and examples.
Constructors
EntityEntry(InternalEntityEntry)
This is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release. You should only use it directly in your code with extreme caution and knowing that doing so can result in application failures when updating to a new Entity Framework Core release.
[EntityFrameworkInternal]
public EntityEntry(InternalEntityEntry internalEntry)
Parameters
internalEntry
InternalEntityEntry
Properties
Collections
Provides access to change tracking information and loading information for all collection navigation properties of this entity.
public virtual IEnumerable<CollectionEntry> Collections { get; }
Property Value
Remarks
See Accessing tracked entities in EF Core and Changing foreign keys and navigations for more information and examples.
ComplexProperties
Provides access to change tracking information and operations for all properties of complex type on this entity.
public virtual IEnumerable<ComplexPropertyEntry> ComplexProperties { get; }
Property Value
Remarks
See Accessing tracked entities in EF Core for more information and examples.
Context
Gets the context that is tracking the entity.
public virtual DbContext Context { get; }
Property Value
CurrentValues
Gets the current property values for this entity.
public virtual PropertyValues CurrentValues { get; }
Property Value
- PropertyValues
The current values.
Remarks
See Accessing tracked entities in EF Core for more information and examples.
DebugView
Expand this property in the debugger for a human-readable view of entry.
Warning: Do not rely on the format of the debug strings. They are designed for debugging only and may change arbitrarily between releases.
public virtual DebugView DebugView { get; }
Property Value
Remarks
See EF Core change tracking and EF Core debug views for more information and examples.
Entity
Gets the entity being tracked by this entry.
public virtual object Entity { get; }
Property Value
InternalEntry
This is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release. You should only use it directly in your code with extreme caution and knowing that doing so can result in application failures when updating to a new Entity Framework Core release.
[EntityFrameworkInternal]
protected virtual InternalEntityEntry InternalEntry { get; }
Property Value
IsKeySet
Gets a value indicating if the key values of this entity have been assigned a value.
public virtual bool IsKeySet { get; }
Property Value
Remarks
For keys with store-generated properties (e.g. mapping to Identity columns), the return value will be false if any of the store-generated properties have the CLR default value.
For keys without any store-generated properties, the return value will always be true since any value is considered a valid key value.
See EF Core change tracking for more information and examples.
Members
Provides access to change tracking information and operations for all properties and navigations of this entity.
public virtual IEnumerable<MemberEntry> Members { get; }
Property Value
Remarks
See Accessing tracked entities in EF Core for more information and examples.
Metadata
Gets the metadata about the shape of the entity, its relationships to other entities, and how it maps to the database.
public virtual IEntityType Metadata { get; }
Property Value
Navigations
Provides access to change tracking information and operations for all navigation properties of this entity.
public virtual IEnumerable<NavigationEntry> Navigations { get; }
Property Value
Remarks
See Accessing tracked entities in EF Core and Changing foreign keys and navigations for more information and examples.
OriginalValues
Gets the original property values for this entity. The original values are the property values as they were when the entity was retrieved from the database.
public virtual PropertyValues OriginalValues { get; }
Property Value
- PropertyValues
The original values.
Remarks
Note that whenever real original property values are not available (e.g. entity was not yet persisted to the database or was retrieved in a non-tracking query) this will default to the current property values of this entity.
See Accessing tracked entities in EF Core for more information and examples.
Properties
Provides access to change tracking information and operations for all properties of this entity.
public virtual IEnumerable<PropertyEntry> Properties { get; }
Property Value
Remarks
See Accessing tracked entities in EF Core for more information and examples.
References
Provides access to change tracking information and loading information for all reference (i.e. non-collection) navigation properties of this entity.
public virtual IEnumerable<ReferenceEntry> References { get; }
Property Value
Remarks
See Accessing tracked entities in EF Core and Changing foreign keys and navigations for more information and examples.
State
Gets or sets that state that this entity is being tracked in.
public virtual EntityState State { get; set; }
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.
Methods
Collection(INavigationBase)
Provides access to change tracking and loading information for a collection navigation that associates this entity to a collection of another entities.
public virtual CollectionEntry Collection(INavigationBase navigation)
Parameters
navigation
INavigationBaseThe collection navigation.
Returns
- CollectionEntry
An object that exposes change tracking information and operations for the given navigation.
Remarks
See Accessing tracked entities in EF Core and Changing foreign keys and navigations for more information and examples.
Collection(string)
Provides access to change tracking and loading information for a collection navigation that associates this entity to a collection of another entities.
public virtual CollectionEntry Collection(string propertyName)
Parameters
propertyName
stringThe name of the navigation.
Returns
- CollectionEntry
An object that exposes change tracking information and operations for the given navigation.
Remarks
See Accessing tracked entities in EF Core and Changing foreign keys and navigations for more information and examples.
ComplexProperty(IComplexProperty)
Provides access to change tracking information and operations for a given property of a complex type on this entity.
public virtual ComplexPropertyEntry ComplexProperty(IComplexProperty property)
Parameters
property
IComplexPropertyThe property to access information and operations for.
Returns
- ComplexPropertyEntry
An object that exposes change tracking information and operations for the given property.
Remarks
See Accessing tracked entities in EF Core for more information and examples.
ComplexProperty(string)
Provides access to change tracking information and operations for a given property of a complex type on this entity.
public virtual ComplexPropertyEntry ComplexProperty(string propertyName)
Parameters
propertyName
stringThe property to access information and operations for.
Returns
- ComplexPropertyEntry
An object that exposes change tracking information and operations for the given property.
Remarks
See Accessing tracked entities in EF Core for more information and examples.
DetectChanges()
Scans this entity instance to detect any changes made to the instance data. DetectChanges() is usually called automatically by the context to get up-to-date information on an individual entity before returning change tracking information. You typically only need to call this method if you have disabled AutoDetectChangesEnabled.
public virtual void DetectChanges()
Remarks
See Change detection and notifications for more information and examples.
GetDatabaseValues()
Queries the database for copies of the values of the tracked entity as they currently exist in the database. If the entity is not found in the database, then null is returned.
public virtual PropertyValues? GetDatabaseValues()
Returns
- PropertyValues
The store values, or null if the entity does not exist in the database.
Remarks
Note that changing the values in the returned dictionary will not update the values in the database.
See Accessing tracked entities in EF Core for more information and examples.
GetDatabaseValuesAsync(CancellationToken)
Queries the database for copies of the values of the tracked entity as they currently exist in the database. If the entity is not found in the database, then null is returned.
public virtual Task<PropertyValues?> GetDatabaseValuesAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenA CancellationToken to observe while waiting for the task to complete.
Returns
- Task<PropertyValues>
A task that represents the asynchronous operation. The task result contains the store values, or null if the entity does not exist in the database.
Remarks
Note that changing the values in the returned dictionary will not update the values in the database.
Multiple active operations on the same context instance are not supported. Use await to ensure that any asynchronous operations have completed before calling another method on this context.
See Accessing tracked entities in EF Core for more information and examples.
Exceptions
- OperationCanceledException
If the CancellationToken is canceled.
Member(IPropertyBase)
Provides access to change tracking information and operations for a given property or navigation of this entity.
public virtual MemberEntry Member(IPropertyBase propertyBase)
Parameters
propertyBase
IPropertyBaseThe property or navigation to access information and operations for.
Returns
- MemberEntry
An object that exposes change tracking information and operations for the given property.
Remarks
See Accessing tracked entities in EF Core for more information and examples.
Member(string)
Provides access to change tracking information and operations for a given property or navigation of this entity.
public virtual MemberEntry Member(string propertyName)
Parameters
propertyName
stringThe property or navigation to access information and operations for.
Returns
- MemberEntry
An object that exposes change tracking information and operations for the given property.
Remarks
See Accessing tracked entities in EF Core for more information and examples.
Navigation(INavigationBase)
Provides access to change tracking information and operations for a given navigation of this entity.
public virtual NavigationEntry Navigation(INavigationBase navigationBase)
Parameters
navigationBase
INavigationBaseThe navigation to access information and operations for.
Returns
- NavigationEntry
An object that exposes change tracking information and operations for the given property.
Remarks
See Accessing tracked entities in EF Core and Changing foreign keys and navigations for more information and examples.
Navigation(string)
Provides access to change tracking information and operations for a given navigation of this entity.
public virtual NavigationEntry Navigation(string propertyName)
Parameters
propertyName
stringThe navigation to access information and operations for.
Returns
- NavigationEntry
An object that exposes change tracking information and operations for the given property.
Remarks
See Accessing tracked entities in EF Core and Changing foreign keys and navigations for more information and examples.
Property(IProperty)
Provides access to change tracking information and operations for a given property of this entity.
public virtual PropertyEntry Property(IProperty property)
Parameters
property
IPropertyThe property to access information and operations for.
Returns
- PropertyEntry
An object that exposes change tracking information and operations for the given property.
Remarks
See Accessing tracked entities in EF Core for more information and examples.
Property(string)
Provides access to change tracking information and operations for a given property of this entity.
public virtual PropertyEntry Property(string propertyName)
Parameters
propertyName
stringThe property to access information and operations for.
Returns
- PropertyEntry
An object that exposes change tracking information and operations for the given property.
Remarks
See Accessing tracked entities in EF Core for more information and examples.
Reference(INavigationBase)
Provides access to change tracking and loading information for a reference (i.e. non-collection) navigation that associates this entity to another entity.
public virtual ReferenceEntry Reference(INavigationBase navigation)
Parameters
navigation
INavigationBaseThe reference navigation.
Returns
- ReferenceEntry
An object that exposes change tracking information and operations for the given navigation.
Remarks
See Accessing tracked entities in EF Core and Changing foreign keys and navigations for more information and examples.
Reference(string)
Provides access to change tracking and loading information for a reference (i.e. non-collection) navigation that associates this entity to another entity.
public virtual ReferenceEntry Reference(string propertyName)
Parameters
propertyName
stringThe name of the navigation.
Returns
- ReferenceEntry
An object that exposes change tracking information and operations for the given navigation.
Remarks
See Accessing tracked entities in EF Core and Changing foreign keys and navigations for more information and examples.
Reload()
Reloads the entity from the database overwriting any property values with values from the database.
public virtual void Reload()
Remarks
The entity will be in the Unchanged state after calling this method, unless the entity does not exist in the database, in which case the entity will be Detached. Finally, calling Reload on an Added entity that does not exist in the database is a no-op. Note, however, that an Added entity may not yet have had its permanent key value created.
See Accessing tracked entities in EF Core for more information and examples.
ReloadAsync(CancellationToken)
Reloads the entity from the database overwriting any property values with values from the database.
public virtual Task ReloadAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenA CancellationToken to observe while waiting for the task to complete.
Returns
- Task
A task that represents the asynchronous operation.
Remarks
The entity will be in the Unchanged state after calling this method, unless the entity does not exist in the database, in which case the entity will be Detached. Finally, calling Reload on an Added entity that does not exist in the database is a no-op. Note, however, that an Added entity may not yet have had its permanent key value created.
See Accessing tracked entities in EF Core for more information and examples.
Exceptions
- OperationCanceledException
If the CancellationToken is canceled.
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.