Table of Contents

Class PropertyValues

Namespace
Microsoft.EntityFrameworkCore.ChangeTracking
Assembly
Microsoft.EntityFrameworkCore.dll

A collection of all property values for an entity.

public abstract class PropertyValues
Inheritance
PropertyValues
Derived
Inherited Members

Remarks

Objects of this type can be obtained from CurrentValues, OriginalValues, GetDatabaseValues(), or GetDatabaseValuesAsync(CancellationToken). Once obtained, the objects are usually used in various combinations to resolve optimistic concurrency exceptions signaled by the throwing of a DbUpdateConcurrencyException.

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

Constructors

PropertyValues(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]
protected PropertyValues(InternalEntityEntry internalEntry)

Parameters

internalEntry InternalEntityEntry

Properties

EntityType

Gets the underlying entity type for which this object is storing values.

public virtual IEntityType EntityType { get; }

Property Value

IEntityType

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

InternalEntityEntry

this[IProperty]

Gets or sets the value of the property.

public abstract object? this[IProperty property] { get; set; }

Parameters

property IProperty

The property.

Property Value

object

The value of the property.

this[string]

Gets or sets the value of the property with the specified property name.

public abstract object? this[string propertyName] { get; set; }

Parameters

propertyName string

The property name.

Property Value

object

The value of the property.

Properties

Gets the properties for which this object is storing values.

public abstract IReadOnlyList<IProperty> Properties { get; }

Property Value

IReadOnlyList<IProperty>

The properties.

Remarks

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

Methods

Clone()

Creates a clone of the values in this object. Changes made to the new object will not be reflected in this object and vice versa.

public abstract PropertyValues Clone()

Returns

PropertyValues

A clone of this object.

Remarks

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

GetValue<TValue>(IProperty)

Gets the value of the property just like using the indexed property getter but typed to the type of the generic parameter.

public abstract TValue GetValue<TValue>(IProperty property)

Parameters

property IProperty

The property.

Returns

TValue

The value of the property.

Type Parameters

TValue

The type of the property.

Remarks

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

GetValue<TValue>(string)

Gets the value of the property just like using the indexed property getter but typed to the type of the generic parameter.

public abstract TValue GetValue<TValue>(string propertyName)

Parameters

propertyName string

The property name.

Returns

TValue

The value of the property.

Type Parameters

TValue

The type of the property.

Remarks

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

SetValues(PropertyValues)

Sets the values of this object by reading values from another PropertyValues object.

public abstract void SetValues(PropertyValues propertyValues)

Parameters

propertyValues PropertyValues

The object from which values should be copied.

Remarks

The other object must be based on the same type as this object, or a type derived from the type for this object.

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

SetValues(object)

Sets the values of this object by copying values from the given object.

public abstract void SetValues(object obj)

Parameters

obj object

The object to read values from.

Remarks

The given object can be of any type. Any property on the object with a name that matches a property name in the entity type and can be read will be copied. Other properties will be ignored. This allows, for example, copying of properties from simple Data Transfer Objects (DTOs).

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

SetValues<TProperty>(IDictionary<string, TProperty>)

Sets the values of this object by copying values from the given dictionary.

public virtual void SetValues<TProperty>(IDictionary<string, TProperty> values)

Parameters

values IDictionary<string, TProperty>

The dictionary to read values from.

Type Parameters

TProperty

Remarks

The keys of the dictionary must match property names. Any key in the dictionary that does not match the name of a property in the entity type will be ignored.

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

ToObject()

Creates an instance of the entity type and sets all its properties using the values from this object.

public abstract object ToObject()

Returns

object

The values of this object copied into a new entity instance.

Remarks

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

TryGetValue<TValue>(string, out TValue)

Try to gets the value of the property just like using the indexed property getter but typed to the type of the generic parameter. If property exists it return the value into the out parameter, otherwise the default value of TValue

public virtual bool TryGetValue<TValue>(string propertyName, out TValue value)

Parameters

propertyName string

The property name.

value TValue

The property value if any.

Returns

bool

True if the property exists, otherwise false.

Type Parameters

TValue

The type of the property.

Remarks

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