Table of Contents

Interface IConventionProperty

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

Represents a scalar property of a structural type.

public interface IConventionProperty : IReadOnlyProperty, IConventionPropertyBase, IReadOnlyPropertyBase, IConventionAnnotatable, IReadOnlyAnnotatable
Inherited Members
Extension Methods

Remarks

This interface is used during model creation and allows the metadata to be modified. Once the model is built, IProperty represents a read-only view of the same metadata.

See Model building conventions for more information and examples.

Properties

Builder

Gets the builder that can be used to configure this property.

IConventionPropertyBuilder Builder { get; }

Property Value

IConventionPropertyBuilder

Exceptions

InvalidOperationException

If the property has been removed from the model.

DeclaringEntityType

Gets the entity type that this property belongs to.

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

Property Value

IConventionEntityType

Methods

FindContainingPrimaryKey()

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

IConventionKey? FindContainingPrimaryKey()

Returns

IConventionKey

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.

IConventionProperty? FindFirstPrincipal()

Returns

IConventionProperty

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

GetAfterSaveBehaviorConfigurationSource()

Returns the configuration source for GetAfterSaveBehavior().

ConfigurationSource? GetAfterSaveBehaviorConfigurationSource()

Returns

ConfigurationSource?

The configuration source for GetAfterSaveBehavior().

GetBeforeSaveBehaviorConfigurationSource()

Returns the configuration source for GetBeforeSaveBehavior().

ConfigurationSource? GetBeforeSaveBehaviorConfigurationSource()

Returns

ConfigurationSource?

The configuration source for GetBeforeSaveBehavior().

GetContainingForeignKeys()

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

IEnumerable<IConventionForeignKey> GetContainingForeignKeys()

Returns

IEnumerable<IConventionForeignKey>

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<IConventionIndex> GetContainingIndexes()

Returns

IEnumerable<IConventionIndex>

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<IConventionKey> GetContainingKeys()

Returns

IEnumerable<IConventionKey>

The primary and alternate keys that use this property.

GetElementType()

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

IConventionElementType? GetElementType()

Returns

IConventionElementType

The configuration for the elements.

GetElementTypeConfigurationSource()

Returns the configuration source for GetElementType().

ConfigurationSource? GetElementTypeConfigurationSource()

Returns

ConfigurationSource?

The configuration source for GetElementType().

GetIsConcurrencyTokenConfigurationSource()

Returns the configuration source for IsConcurrencyToken.

ConfigurationSource? GetIsConcurrencyTokenConfigurationSource()

Returns

ConfigurationSource?

The configuration source for IsConcurrencyToken.

GetIsNullableConfigurationSource()

Returns the configuration source for IsNullable.

ConfigurationSource? GetIsNullableConfigurationSource()

Returns

ConfigurationSource?

The configuration source for IsNullable.

GetIsUnicodeConfigurationSource()

Returns the configuration source for IsUnicode().

ConfigurationSource? GetIsUnicodeConfigurationSource()

Returns

ConfigurationSource?

The configuration source for IsUnicode().

GetJsonValueReaderWriterTypeConfigurationSource()

Returns the configuration source for GetJsonValueReaderWriter().

ConfigurationSource? GetJsonValueReaderWriterTypeConfigurationSource()

Returns

ConfigurationSource?

The configuration source for GetJsonValueReaderWriter().

GetMaxLengthConfigurationSource()

Returns the configuration source for GetMaxLength().

ConfigurationSource? GetMaxLengthConfigurationSource()

Returns

ConfigurationSource?

The configuration source for GetMaxLength().

GetPrecisionConfigurationSource()

Returns the configuration source for GetPrecision().

ConfigurationSource? GetPrecisionConfigurationSource()

Returns

ConfigurationSource?

The configuration source for GetPrecision().

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<IConventionProperty> GetPrincipals()

Returns

IReadOnlyList<IConventionProperty>

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

GetProviderClrTypeConfigurationSource()

Returns the configuration source for GetProviderClrType().

ConfigurationSource? GetProviderClrTypeConfigurationSource()

Returns

ConfigurationSource?

The configuration source for GetProviderClrType().

GetProviderValueComparerConfigurationSource()

Returns the configuration source for GetProviderValueComparer().

ConfigurationSource? GetProviderValueComparerConfigurationSource()

Returns

ConfigurationSource?

The configuration source for GetProviderValueComparer().

GetScaleConfigurationSource()

Returns the configuration source for GetScale().

ConfigurationSource? GetScaleConfigurationSource()

Returns

ConfigurationSource?

The configuration source for GetScale().

GetSentinelConfigurationSource()

Returns the configuration source for Sentinel.

ConfigurationSource? GetSentinelConfigurationSource()

Returns

ConfigurationSource?

The configuration source for Sentinel.

GetTypeConfigurationSource()

Returns the configuration source for ClrType.

ConfigurationSource? GetTypeConfigurationSource()

Returns

ConfigurationSource?

The configuration source for ClrType.

GetTypeMappingConfigurationSource()

Gets the ConfigurationSource for CoreTypeMapping of the property.

ConfigurationSource? GetTypeMappingConfigurationSource()

Returns

ConfigurationSource?

The ConfigurationSource for CoreTypeMapping of the property.

GetValueComparerConfigurationSource()

Returns the configuration source for GetValueComparer().

ConfigurationSource? GetValueComparerConfigurationSource()

Returns

ConfigurationSource?

The configuration source for GetValueComparer().

GetValueConverterConfigurationSource()

Returns the configuration source for GetValueConverter().

ConfigurationSource? GetValueConverterConfigurationSource()

Returns

ConfigurationSource?

The configuration source for GetValueConverter().

GetValueGeneratedConfigurationSource()

Returns the configuration source for ValueGenerated.

ConfigurationSource? GetValueGeneratedConfigurationSource()

Returns

ConfigurationSource?

The configuration source for ValueGenerated.

GetValueGeneratorFactoryConfigurationSource()

Returns the configuration source for GetValueGeneratorFactory().

ConfigurationSource? GetValueGeneratorFactoryConfigurationSource()

Returns

ConfigurationSource?

The configuration source for GetValueGeneratorFactory().

IsImplicitlyCreated()

Returns a value indicating whether the property was created implicitly and isn't based on the CLR model.

bool IsImplicitlyCreated()

Returns

bool

A value indicating whether the property was created implicitly and isn't based on the CLR model.

SetAfterSaveBehavior(PropertySaveBehavior?, bool)

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

PropertySaveBehavior? SetAfterSaveBehavior(PropertySaveBehavior? afterSaveBehavior, bool fromDataAnnotation = false)

Parameters

afterSaveBehavior PropertySaveBehavior?

Sets a value indicating whether this property can be modified after the entity is saved to the database. null to reset to default.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

PropertySaveBehavior?

The configured value.

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.

SetBeforeSaveBehavior(PropertySaveBehavior?, bool)

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

PropertySaveBehavior? SetBeforeSaveBehavior(PropertySaveBehavior? beforeSaveBehavior, bool fromDataAnnotation = false)

Parameters

beforeSaveBehavior PropertySaveBehavior?

A value indicating whether this property can be modified before the entity is saved to the database. null to reset to default.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

PropertySaveBehavior?

The configured value.

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.

SetElementType(Type?, bool)

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

IConventionElementType? SetElementType(Type? elementType, bool fromDataAnnotation = false)

Parameters

elementType Type

If true, then the type mapping has an element type, otherwise it is removed.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionElementType

The configuration for the elements.

SetIsConcurrencyToken(bool?, bool)

Sets 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? SetIsConcurrencyToken(bool? concurrencyToken, bool fromDataAnnotation = false)

Parameters

concurrencyToken bool?

Sets a value indicating whether this property is used as a concurrency token. null to reset to default.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool?

The configured value.

SetIsNullable(bool?, bool)

Sets a value indicating whether this property can contain null.

bool? SetIsNullable(bool? nullable, bool fromDataAnnotation = false)

Parameters

nullable bool?

A value indicating whether this property can contain null. null to reset to default.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool?

The configured value.

SetIsUnicode(bool?, bool)

Sets a value indicating whether this property can persist Unicode characters.

bool? SetIsUnicode(bool? unicode, bool fromDataAnnotation = false)

Parameters

unicode bool?

true if the property accepts Unicode characters, false if it does not, null to clear the setting.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool?

The configured value.

SetJsonValueReaderWriterType(Type?, bool)

Sets the type of JsonValueReaderWriter<TValue> to use for this property.

Type? SetJsonValueReaderWriterType(Type? readerWriterType, bool fromDataAnnotation = false)

Parameters

readerWriterType Type

A type that inherits from JsonValueReaderWriter<TValue>, or null to use the reader/writer from the type mapping.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

Type

The configured value.

SetMaxLength(int?, bool)

Sets 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? SetMaxLength(int? maxLength, bool fromDataAnnotation = false)

Parameters

maxLength int?

The maximum length of data that is allowed in this property.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

int?

The configured property.

SetPrecision(int?, bool)

Sets 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? SetPrecision(int? precision, bool fromDataAnnotation = false)

Parameters

precision int?

The maximum number of digits that is allowed in this property.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

int?

SetProviderClrType(Type?, bool)

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

Type? SetProviderClrType(Type? providerClrType, bool fromDataAnnotation = false)

Parameters

providerClrType Type

The type to use, or null to remove any previously set type.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

Type

The configured value.

SetProviderValueComparer(ValueComparer?, bool)

Sets the custom ValueComparer to use for the provider values for this property.

ValueComparer? SetProviderValueComparer(ValueComparer? comparer, bool fromDataAnnotation = false)

Parameters

comparer ValueComparer

The comparer, or null to remove any previously set comparer.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

ValueComparer

The configured value.

SetProviderValueComparer(Type?, bool)

Sets the custom ValueComparer to use for the provider values for this property.

Type? SetProviderValueComparer(Type? comparerType, bool fromDataAnnotation = false)

Parameters

comparerType Type

A type that inherits from ValueComparer, or null to remove any previously set comparer.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

Type

The configured value.

SetScale(int?, bool)

Sets 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? SetScale(int? scale, bool fromDataAnnotation = false)

Parameters

scale int?

The maximum number of decimal places that is allowed in this property.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

int?

SetSentinel(object?, bool)

Sets the sentinel value that indicates that this property is not set.

object? SetSentinel(object? sentinel, bool fromDataAnnotation = false)

Parameters

sentinel object

The sentinel value.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

object

The configured value.

SetTypeMapping(CoreTypeMapping, bool)

Sets the CoreTypeMapping for the given property

CoreTypeMapping? SetTypeMapping(CoreTypeMapping typeMapping, bool fromDataAnnotation = false)

Parameters

typeMapping CoreTypeMapping

The CoreTypeMapping for this property.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

CoreTypeMapping

SetValueComparer(ValueComparer?, bool)

Sets the custom ValueComparer for this property.

ValueComparer? SetValueComparer(ValueComparer? comparer, bool fromDataAnnotation = false)

Parameters

comparer ValueComparer

The comparer, or null to remove any previously set comparer.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

ValueComparer

The configured value.

SetValueComparer(Type?, bool)

Sets the custom ValueComparer for this property.

Type? SetValueComparer(Type? comparerType, bool fromDataAnnotation = false)

Parameters

comparerType Type

A type that inherits from ValueComparer, or null to remove any previously set comparer.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

Type

The configured value.

SetValueConverter(ValueConverter?, bool)

Sets the custom ValueConverter for this property.

ValueConverter? SetValueConverter(ValueConverter? converter, bool fromDataAnnotation = false)

Parameters

converter ValueConverter

The converter, or null to remove any previously set converter.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

ValueConverter

The configured value.

SetValueConverter(Type?, bool)

Sets the custom ValueConverter for this property.

Type? SetValueConverter(Type? converterType, bool fromDataAnnotation = false)

Parameters

converterType Type

A type that inherits from ValueConverter, or null to remove any previously set converter.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

Type

The configured value.

SetValueGenerated(ValueGenerated?, bool)

Sets 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? SetValueGenerated(ValueGenerated? valueGenerated, bool fromDataAnnotation = false)

Parameters

valueGenerated ValueGenerated?

A value indicating when a value for this property will be generated by the database. null to reset to default.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

ValueGenerated?

The configured value.

SetValueGeneratorFactory(Func<IProperty, ITypeBase, ValueGenerator>?, bool)

Sets the factory to use for generating values for this property, or null to clear any previously set factory.

Func<IProperty, ITypeBase, ValueGenerator>? SetValueGeneratorFactory(Func<IProperty, ITypeBase, ValueGenerator>? valueGeneratorFactory, bool fromDataAnnotation = false)

Parameters

valueGeneratorFactory Func<IProperty, ITypeBase, ValueGenerator>

A factory that will be used to create the value generator, or null to clear any previously set factory.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

Func<IProperty, ITypeBase, ValueGenerator>

The configured value.

Remarks

Setting null does not disable value generation for this property, it just clears any generator explicitly configured for this property. The database provider may still have a value generator for the property type.

SetValueGeneratorFactory(Type?, bool)

Sets the factory to use for generating values for this property, or null to clear any previously set factory.

Type? SetValueGeneratorFactory(Type? valueGeneratorFactory, bool fromDataAnnotation = false)

Parameters

valueGeneratorFactory Type

A factory that will be used to create the value generator, or null to clear any previously set factory.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

Type

The configured value.

Remarks

Setting null does not disable value generation for this property, it just clears any generator explicitly configured for this property. The database provider may still have a value generator for the property type.