Interface IMutableProperty
- Namespace
- Microsoft.EntityFrameworkCore.Metadata
- Assembly
- Microsoft.EntityFrameworkCore.dll
Represents a scalar property of a structural type.
public interface IMutableProperty : IReadOnlyProperty, IMutablePropertyBase, IReadOnlyPropertyBase, IMutableAnnotatable, 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 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 IMutableEntityType or IMutableComplexType")]
IMutableEntityType DeclaringEntityType { get; }
Property Value
IsConcurrencyToken
Gets or 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 IsConcurrencyToken { get; set; }
Property Value
IsNullable
Gets or sets a value indicating whether this property can contain null.
bool IsNullable { get; set; }
Property Value
Sentinel
Gets or sets the sentinel value that indicates that this property is not set.
object? Sentinel { get; set; }
Property Value
ValueGenerated
Gets or 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 ValueGenerated { get; set; }
Property Value
Methods
FindContainingPrimaryKey()
Gets the primary key that uses this property (including a composite primary key in which this property is included).
IMutableKey? FindContainingPrimaryKey()
Returns
- IMutableKey
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.
IMutableProperty? FindFirstPrincipal()
Returns
- IMutableProperty
The first associated principal property, or null if none exists.
GetContainingForeignKeys()
Gets all foreign keys that use this property (including composite foreign keys in which this property is included).
IEnumerable<IMutableForeignKey> GetContainingForeignKeys()
Returns
- IEnumerable<IMutableForeignKey>
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<IMutableIndex> GetContainingIndexes()
Returns
- IEnumerable<IMutableIndex>
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<IMutableKey> GetContainingKeys()
Returns
- IEnumerable<IMutableKey>
The primary and alternate keys that use this property.
GetElementType()
Gets the configuration for elements of the primitive collection represented by this property.
IMutableElementType? GetElementType()
Returns
- IMutableElementType
The configuration for the elements.
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<IMutableProperty> GetPrincipals()
Returns
- IReadOnlyList<IMutableProperty>
The list of all associated principal properties including the given property.
SetAfterSaveBehavior(PropertySaveBehavior?)
Gets or sets a value indicating whether this property can be modified after the entity is saved to the database.
void SetAfterSaveBehavior(PropertySaveBehavior? afterSaveBehavior)
Parameters
afterSaveBehavior
PropertySaveBehavior?A value indicating whether this property can be modified after the entity is saved to the database.
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?)
Gets or sets a value indicating whether this property can be modified before the entity is saved to the database.
void SetBeforeSaveBehavior(PropertySaveBehavior? beforeSaveBehavior)
Parameters
beforeSaveBehavior
PropertySaveBehavior?A value indicating whether this property can be modified before the entity is saved to the database.
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?)
Sets the configuration for elements of the primitive collection represented by this property.
void SetElementType(Type? elementType)
Parameters
SetIsUnicode(bool?)
Sets a value indicating whether this property can persist Unicode characters.
void SetIsUnicode(bool? unicode)
Parameters
unicode
bool?true if the property accepts Unicode characters, false if it does not, null to clear the setting.
SetJsonValueReaderWriterType(Type?)
Sets the type of JsonValueReaderWriter<TValue> to use for this property for this property.
void SetJsonValueReaderWriterType(Type? readerWriterType)
Parameters
readerWriterType
TypeA type that derives from JsonValueReaderWriter<TValue>, or null to use the reader/writer from the type mapping.
SetMaxLength(int?)
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.
void SetMaxLength(int? maxLength)
Parameters
maxLength
int?The maximum length of data that is allowed in this property.
SetPrecision(int?)
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.
void SetPrecision(int? precision)
Parameters
precision
int?The maximum number of digits that is allowed in this property.
SetProviderClrType(Type?)
Sets the type that the property value will be converted to before being sent to the database provider.
void SetProviderClrType(Type? providerClrType)
Parameters
SetProviderValueComparer(ValueComparer?)
Sets the custom ValueComparer to use for the provider values for this property.
void SetProviderValueComparer(ValueComparer? comparer)
Parameters
comparer
ValueComparerThe comparer, or null to remove any previously set comparer.
SetProviderValueComparer(Type?)
Sets the custom ValueComparer to use for the provider values for this property.
void SetProviderValueComparer(Type? comparerType)
Parameters
comparerType
TypeA type that derives from ValueComparer, or null to remove any previously set comparer.
SetScale(int?)
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.
void SetScale(int? scale)
Parameters
scale
int?The maximum number of decimal places that is allowed in this property.
SetTypeMapping(CoreTypeMapping)
Sets the CoreTypeMapping for the given property
void SetTypeMapping(CoreTypeMapping typeMapping)
Parameters
typeMapping
CoreTypeMappingThe CoreTypeMapping for this property.
SetValueComparer(ValueComparer?)
Sets the custom ValueComparer for this property.
void SetValueComparer(ValueComparer? comparer)
Parameters
comparer
ValueComparerThe comparer, or null to remove any previously set comparer.
SetValueComparer(Type?)
Sets the custom ValueComparer for this property.
void SetValueComparer(Type? comparerType)
Parameters
comparerType
TypeA type that derives from ValueComparer, or null to remove any previously set comparer.
SetValueConverter(ValueConverter?)
Sets the custom ValueConverter for this property.
void SetValueConverter(ValueConverter? converter)
Parameters
converter
ValueConverterThe converter, or null to remove any previously set converter.
SetValueConverter(Type?)
Sets the custom ValueConverter for this property.
void SetValueConverter(Type? converterType)
Parameters
converterType
TypeA type that derives from ValueConverter, or null to remove any previously set converter.
SetValueGeneratorFactory(Func<IProperty, ITypeBase, ValueGenerator>?)
Sets the factory to use for generating values for this property, or null to clear any previously set factory.
void SetValueGeneratorFactory(Func<IProperty, ITypeBase, ValueGenerator>? valueGeneratorFactory)
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.
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?)
Sets the factory to use for generating values for this property, or null to clear any previously set factory.
void SetValueGeneratorFactory(Type? valueGeneratorFactory)
Parameters
valueGeneratorFactory
TypeA factory that will be used to create the value generator, or null to clear any previously set factory.
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.