Table of Contents

Interface IReadOnlyProperty

Namespace
Microsoft.EntityFrameworkCore.Metadata
Assembly
Microsoft.EntityFrameworkCore.dll

Represents a scalar property of a structural type.

public interface IReadOnlyProperty : IReadOnlyPropertyBase, IReadOnlyAnnotatable
Inherited Members
Extension Methods

Remarks

See Modeling entity types and relationships for more information and examples.

Properties

DeclaringEntityType

Gets the entity type that this property belongs to.

[Obsolete("Use DeclaringType and cast to IReadOnlyEntityType or IReadOnlyComplexType")]
IReadOnlyEntityType DeclaringEntityType { get; }

Property Value

IReadOnlyEntityType

IsConcurrencyToken

Gets a value indicating whether this property is used as a concurrency token. When a property is configured as a concurrency token the value in the database will be checked when an instance of this entity type is updated or deleted during SaveChanges() to ensure it has not changed since the instance was retrieved from the database. If it has changed, an exception will be thrown and the changes will not be applied to the database.

bool IsConcurrencyToken { get; }

Property Value

bool

IsNullable

Gets a value indicating whether this property can contain null.

bool IsNullable { get; }

Property Value

bool

IsPrimitiveCollection

A property is a primitive collection if it has an element type that matches the element type of the CLR type.

bool IsPrimitiveCollection { get; }

Property Value

bool

true if the property represents a primitive collection.

ValueGenerated

Gets a value indicating when a value for this property will be generated by the database. Even when the property is set to be generated by the database, EF may still attempt to save a specific value (rather than having one generated by the database) when the entity is added and a value is assigned, or the property is marked as modified for an existing entity. See GetBeforeSaveBehavior() and GetAfterSaveBehavior() for more information and examples.

ValueGenerated ValueGenerated { get; }

Property Value

ValueGenerated

Methods

FindContainingPrimaryKey()

Gets the primary key that uses this property (including a composite primary key in which this property is included).

IReadOnlyKey? FindContainingPrimaryKey()

Returns

IReadOnlyKey

The primary that use this property, or null if it is not part of the primary key.

FindFirstPrincipal()

Finds the first principal property that the given property is constrained by if the given property is part of a foreign key.

IReadOnlyProperty? FindFirstPrincipal()

Returns

IReadOnlyProperty

The first associated principal property, or null if none exists.

FindTypeMapping()

Returns the type mapping for this property.

CoreTypeMapping? FindTypeMapping()

Returns

CoreTypeMapping

The type mapping, or null if none was found.

GetAfterSaveBehavior()

Gets a value indicating whether or not this property can be modified after the entity is saved to the database.

PropertySaveBehavior GetAfterSaveBehavior()

Returns

PropertySaveBehavior

The after save behavior for this property.

Remarks

If Throw, then an exception will be thrown if a new value is assigned to this property after the entity exists in the database.

If Ignore, then any modification to the property value of an entity that already exists in the database will be ignored.

GetBeforeSaveBehavior()

Gets a value indicating whether or not this property can be modified before the entity is saved to the database.

PropertySaveBehavior GetBeforeSaveBehavior()

Returns

PropertySaveBehavior

The before save behavior for this property.

Remarks

If Throw, then an exception will be thrown if a value is assigned to this property when it is in the Added state.

If Ignore, then any value set will be ignored when it is in the Added state.

GetContainingForeignKeys()

Gets all foreign keys that use this property (including composite foreign keys in which this property is included).

IEnumerable<IReadOnlyForeignKey> GetContainingForeignKeys()

Returns

IEnumerable<IReadOnlyForeignKey>

The foreign keys that use this property.

GetContainingIndexes()

Gets all indexes that use this property (including composite indexes in which this property is included).

IEnumerable<IReadOnlyIndex> GetContainingIndexes()

Returns

IEnumerable<IReadOnlyIndex>

The indexes that use this property.

GetContainingKeys()

Gets all primary or alternate keys that use this property (including composite keys in which this property is included).

IEnumerable<IReadOnlyKey> GetContainingKeys()

Returns

IEnumerable<IReadOnlyKey>

The primary and alternate keys that use this property.

GetElementType()

Gets the configuration for elements of the primitive collection represented by this property.

IReadOnlyElementType? GetElementType()

Returns

IReadOnlyElementType

The configuration for the elements.

GetJsonValueReaderWriter()

Gets the JsonValueReaderWriter for this property, or null if none is set.

JsonValueReaderWriter? GetJsonValueReaderWriter()

Returns

JsonValueReaderWriter

The reader/writer, or null if none has been set.

GetKeyValueComparer()

Gets the ValueComparer to use with keys for this property, or null if none is set.

ValueComparer? GetKeyValueComparer()

Returns

ValueComparer

The comparer, or null if none has been set.

GetMaxLength()

Gets the maximum length of data that is allowed in this property. For example, if the property is a string then this is the maximum number of characters.

int? GetMaxLength()

Returns

int?

The maximum length, -1 if the property has no maximum length, or null if the maximum length hasn't been set.

GetPrecision()

Gets the precision of data that is allowed in this property. For example, if the property is a decimal then this is the maximum number of digits.

int? GetPrecision()

Returns

int?

The precision, or null if none is defined.

GetPrincipals()

Finds the list of principal properties including the given property that the given property is constrained by if the given property is part of a foreign key.

IReadOnlyList<IReadOnlyProperty> GetPrincipals()

Returns

IReadOnlyList<IReadOnlyProperty>

The list of all associated principal properties including the given property.

GetPrincipals<T>()

Finds the list of principal properties including the given property that the given property is constrained by if the given property is part of a foreign key.

IReadOnlyList<T> GetPrincipals<T>() where T : IReadOnlyProperty

Returns

IReadOnlyList<T>

The list of all associated principal properties including the given property.

Type Parameters

T

GetProviderClrType()

Gets the type that the property value will be converted to before being sent to the database provider.

Type? GetProviderClrType()

Returns

Type

The provider type, or null if none has been set.

GetProviderValueComparer()

Gets the ValueComparer to use for the provider values for this property.

ValueComparer? GetProviderValueComparer()

Returns

ValueComparer

The comparer, or null if none has been set.

GetScale()

Gets the scale of data that is allowed in this property. For example, if the property is a decimal then this is the maximum number of decimal places.

int? GetScale()

Returns

int?

The scale, or null if none is defined.

GetTypeMapping()

Returns the CoreTypeMapping for the given property from a finalized model.

CoreTypeMapping GetTypeMapping()

Returns

CoreTypeMapping

The type mapping.

GetValueComparer()

Gets the ValueComparer for this property, or null if none is set.

ValueComparer? GetValueComparer()

Returns

ValueComparer

The comparer, or null if none has been set.

GetValueConverter()

Gets the custom ValueConverter set for this property.

ValueConverter? GetValueConverter()

Returns

ValueConverter

The converter, or null if none has been set.

GetValueGeneratorFactory()

Gets the factory that has been set to generate values for this property, if any.

Func<IProperty, ITypeBase, ValueGenerator>? GetValueGeneratorFactory()

Returns

Func<IProperty, ITypeBase, ValueGenerator>

The factory, or null if no factory has been set.

IsForeignKey()

Gets a value indicating whether this property is used as a foreign key (or part of a composite foreign key).

bool IsForeignKey()

Returns

bool

true if the property is used as a foreign key, otherwise false.

IsIndex()

Gets a value indicating whether this property is used as an index (or part of a composite index).

bool IsIndex()

Returns

bool

true if the property is used as an index, otherwise false.

IsKey()

Gets a value indicating whether this property is used as the primary key or alternate key (or part of a composite primary or alternate key).

bool IsKey()

Returns

bool

true if the property is used as a key, otherwise false.

IsPrimaryKey()

Gets a value indicating whether this property is used as the primary key (or part of a composite primary key).

bool IsPrimaryKey()

Returns

bool

true if the property is used as the primary key, otherwise false.

IsUnicode()

Gets a value indicating whether or not the property can persist Unicode characters.

bool? IsUnicode()

Returns

bool?

The Unicode setting, or null if none is defined.

IsUniqueIndex()

Gets a value indicating whether this property is used as a unique index (or part of a unique composite index).

bool IsUniqueIndex()

Returns

bool

true if the property is used as an unique index, otherwise false.

ToDebugString(MetadataDebugStringOptions, int)

Creates a human-readable representation of the given metadata.

Warning: Do not rely on the format of the returned string. It is designed for debugging only and may change arbitrarily between releases.

string ToDebugString(MetadataDebugStringOptions options = MetadataDebugStringOptions.ShortDefault, int indent = 0)

Parameters

options MetadataDebugStringOptions

Options for generating the string.

indent int

The number of indent spaces to use before each new line.

Returns

string

A human-readable representation.