Interface IConventionPropertyBuilder
- Namespace
- Microsoft.EntityFrameworkCore.Metadata.Builders
- Assembly
- Microsoft.EntityFrameworkCore.dll
Provides a simple API surface for configuring an IConventionProperty from conventions.
This interface is typically used by database providers (and other extensions). It is generally not used in application code.
public interface IConventionPropertyBuilder : IConventionPropertyBaseBuilder<IConventionPropertyBuilder>, IConventionAnnotatableBuilder
- Inherited Members
Remarks
See Model building conventions for more information and examples.
Properties
Metadata
Gets the property being configured.
IConventionProperty Metadata { get; }
Property Value
Methods
AfterSave(PropertySaveBehavior?, bool)
Configures whether this property can be modified after the entity is saved to the database.
IConventionPropertyBuilder? AfterSave(PropertySaveBehavior? behavior, bool fromDataAnnotation = false)
Parameters
behavior
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
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionPropertyBuilder
The same builder instance if the configuration was applied, null otherwise.
BeforeSave(PropertySaveBehavior?, bool)
Configures whether this property can be modified before the entity is saved to the database.
IConventionPropertyBuilder? BeforeSave(PropertySaveBehavior? behavior, bool fromDataAnnotation = false)
Parameters
behavior
PropertySaveBehavior?A value indicating whether this property can be modified before the entity is saved to the database. null to reset to default.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionPropertyBuilder
The same builder instance if the configuration was applied, null otherwise.
CanSetAfterSave(PropertySaveBehavior?, bool)
Returns a value indicating whether the ability to be modified after the entity is saved to the database can be configured for this property from the current configuration source.
bool CanSetAfterSave(PropertySaveBehavior? behavior, bool fromDataAnnotation = false)
Parameters
behavior
PropertySaveBehavior?A value indicating whether this property can be modified after the entity is saved to the database. null to reset to default.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- bool
true if the ability to be modified after the entity is saved to the database can be configured for this property.
CanSetBeforeSave(PropertySaveBehavior?, bool)
Returns a value indicating whether the ability to be modified before the entity is saved to the database can be configured for this property from the current configuration source.
bool CanSetBeforeSave(PropertySaveBehavior? behavior, bool fromDataAnnotation = false)
Parameters
behavior
PropertySaveBehavior?A value indicating whether this property can be modified before the entity is saved to the database. null to reset to default.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- bool
true if the ability to be modified before the entity is saved to the database can be configured for this property.
CanSetConversion(ValueConverter?, bool)
Returns a value indicating whether the ValueConverter can be configured for this property from the current configuration source.
bool CanSetConversion(ValueConverter? converter, bool fromDataAnnotation = false)
Parameters
converter
ValueConverterThe converter to use.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- bool
true if the ValueConverter can be configured for this property.
CanSetConversion(Type?, bool)
Returns a value indicating whether the given type to convert values to and from can be configured for this property from the current configuration source.
bool CanSetConversion(Type? providerClrType, bool fromDataAnnotation = false)
Parameters
providerClrType
TypeThe type to convert to and from.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
CanSetConverter(Type?, bool)
Returns a value indicating whether the ValueConverter can be configured for this property from the current configuration source.
bool CanSetConverter(Type? converterType, bool fromDataAnnotation = false)
Parameters
converterType
TypeA type that derives from ValueConverter, or null to remove any previously set converter.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- bool
true if the ValueConverter can be configured for this property.
CanSetElementType(Type?, bool)
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.
bool CanSetElementType(Type? elementType, bool fromDataAnnotation = false)
Parameters
Returns
CanSetIsConcurrencyToken(bool?, bool)
Returns a value indicating whether the property can be configured as a concurrency token from the current configuration source.
bool CanSetIsConcurrencyToken(bool? concurrencyToken, bool fromDataAnnotation = false)
Parameters
concurrencyToken
bool?A value indicating whether this property is a concurrency token.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
CanSetIsRequired(bool?, bool)
Returns a value indicating whether this property requiredness can be configured from the current configuration source.
bool CanSetIsRequired(bool? required, bool fromDataAnnotation = false)
Parameters
required
bool?A value indicating whether the property is required. null to reset to default.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
CanSetIsUnicode(bool?, bool)
Returns a value indicating whether the property can be configured as capable of persisting unicode characters from the current configuration source.
bool CanSetIsUnicode(bool? unicode, bool fromDataAnnotation = false)
Parameters
unicode
bool?A value indicating whether the property can contain unicode characters.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
CanSetMaxLength(int?, bool)
Returns a value indicating whether the maximum length of data allowed can be set for this property from the current configuration source.
bool CanSetMaxLength(int? maxLength, bool fromDataAnnotation = false)
Parameters
maxLength
int?The maximum length of data allowed in the property.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
CanSetPrecision(int?, bool)
Returns a value indicating whether the precision of data allowed can be set for this property from the current configuration source.
bool CanSetPrecision(int? precision, bool fromDataAnnotation = false)
Parameters
precision
int?The precision of the property.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
CanSetProviderValueComparer(ValueComparer?, bool)
Returns a value indicating whether the given ValueComparer can be configured for this property from the current configuration source.
bool CanSetProviderValueComparer(ValueComparer? comparer, bool fromDataAnnotation = false)
Parameters
comparer
ValueComparerThe comparer, or null to remove any previously set comparer.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- bool
true if the given ValueComparer can be configured for this property.
CanSetProviderValueComparer(Type?, bool)
Returns a value indicating whether the given ValueComparer can be configured for this property from the current configuration source.
bool CanSetProviderValueComparer(Type? comparerType, bool fromDataAnnotation = false)
Parameters
comparerType
TypeA type that derives from ValueComparer, or null to remove any previously set comparer.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- bool
true if the given ValueComparer can be configured for this property.
CanSetScale(int?, bool)
Returns a value indicating whether the scale of data allowed can be set for this property from the current configuration source.
bool CanSetScale(int? scale, bool fromDataAnnotation = false)
Parameters
scale
int?The scale of the property.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
CanSetSentinel(object?, bool)
Returns a value indicating whether the sentinel can be set for this property from the current configuration source.
bool CanSetSentinel(object? sentinel, bool fromDataAnnotation = false)
Parameters
sentinel
objectThe sentinel value.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
CanSetTypeMapping(CoreTypeMapping, bool)
Returns a value indicating whether the given CoreTypeMapping can be configured for this property from the current configuration source.
bool CanSetTypeMapping(CoreTypeMapping typeMapping, bool fromDataAnnotation = false)
Parameters
typeMapping
CoreTypeMappingThe type mapping.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- bool
true if the given ValueComparer can be configured for this property.
CanSetValueComparer(ValueComparer?, bool)
Returns a value indicating whether the given ValueComparer can be configured for this property from the current configuration source.
bool CanSetValueComparer(ValueComparer? comparer, bool fromDataAnnotation = false)
Parameters
comparer
ValueComparerThe comparer, or null to remove any previously set comparer.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- bool
true if the given ValueComparer can be configured for this property.
CanSetValueComparer(Type?, bool)
Returns a value indicating whether the given ValueComparer can be configured for this property from the current configuration source.
bool CanSetValueComparer(Type? comparerType, bool fromDataAnnotation = false)
Parameters
comparerType
TypeA type that derives from ValueComparer, or null to remove any previously set comparer.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- bool
true if the given ValueComparer can be configured for this property.
CanSetValueGenerated(ValueGenerated?, bool)
Returns a value indicating whether the property value generation can be configured from the current configuration source.
bool CanSetValueGenerated(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
boolIndicates whether the configuration was specified using a data annotation.
Returns
CanSetValueGenerator(Func<IProperty, ITypeBase, ValueGenerator>?, bool)
Returns a value indicating whether the ValueGenerator can be configured for this property from the current configuration source.
bool CanSetValueGenerator(Func<IProperty, ITypeBase, ValueGenerator>? factory, bool fromDataAnnotation = false)
Parameters
factory
Func<IProperty, ITypeBase, ValueGenerator>A delegate that will be used to create value generator instances.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
CanSetValueGeneratorFactory(Type?, bool)
Returns a value indicating whether the ValueGeneratorFactory can be configured for this property from the current configuration source.
bool CanSetValueGeneratorFactory(Type? valueGeneratorFactoryType, bool fromDataAnnotation = false)
Parameters
valueGeneratorFactoryType
TypeA type that inherits from ValueGeneratorFactory.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
HasConversion(ValueConverter?, bool)
Configures the property so that the property value is converted to and from the database using the given ValueConverter.
IConventionPropertyBuilder? HasConversion(ValueConverter? converter, bool fromDataAnnotation = false)
Parameters
converter
ValueConverterThe converter to use.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionPropertyBuilder
The same builder instance if the configuration was applied, null otherwise.
HasConversion(Type?, bool)
Configures the property so that the property value is converted to the given type before writing to the database and converted back when reading from the database.
IConventionPropertyBuilder? HasConversion(Type? providerClrType, bool fromDataAnnotation = false)
Parameters
providerClrType
TypeThe type to convert to and from.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionPropertyBuilder
The same builder instance if the configuration was applied, null otherwise.
HasConverter(Type?, bool)
Configures the property so that the property value is converted to and from the database using the given ValueConverter.
IConventionPropertyBuilder? HasConverter(Type? converterType, bool fromDataAnnotation = false)
Parameters
converterType
TypeA type that derives from ValueConverter, or null to remove any previously set converter.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionPropertyBuilder
The same builder instance if the configuration was applied, null otherwise.
HasMaxLength(int?, bool)
Configures the maximum length of data that can be stored in this property.
IConventionPropertyBuilder? HasMaxLength(int? maxLength, bool fromDataAnnotation = false)
Parameters
maxLength
int?The maximum length of data allowed in the property. A value of
-1
indicates that the property has no maximum length.fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionPropertyBuilder
The same builder instance if the configuration was applied, null otherwise.
HasPrecision(int?, bool)
Configures the precision of the property.
IConventionPropertyBuilder? HasPrecision(int? precision, bool fromDataAnnotation = false)
Parameters
precision
int?The precision of the property.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionPropertyBuilder
The same builder instance if the configuration was applied, null otherwise.
HasProviderValueComparer(ValueComparer?, bool)
Configures the ValueComparer to use for the provider values for this property.
IConventionPropertyBuilder? HasProviderValueComparer(ValueComparer? comparer, bool fromDataAnnotation = false)
Parameters
comparer
ValueComparerThe comparer, or null to remove any previously set comparer.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionPropertyBuilder
The same builder instance if the configuration was applied, null otherwise.
HasProviderValueComparer(Type?, bool)
Configures the ValueComparer to use for the provider values for this property.
IConventionPropertyBuilder? HasProviderValueComparer(Type? comparerType, bool fromDataAnnotation = false)
Parameters
comparerType
TypeA type that derives from ValueComparer, or null to remove any previously set comparer.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionPropertyBuilder
The same builder instance if the configuration was applied, null otherwise.
HasScale(int?, bool)
Configures the scale of the property.
IConventionPropertyBuilder? HasScale(int? scale, bool fromDataAnnotation = false)
Parameters
scale
int?The scale of the property.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionPropertyBuilder
The same builder instance if the configuration was applied, null otherwise.
HasSentinel(object?, bool)
Configures the value that will be used to determine if the property has been set or not. If the property is set to the sentinel value, then it is considered not set. By default, the sentinel value is the CLR default value for the type of the property.
IConventionPropertyBuilder? HasSentinel(object? sentinel, bool fromDataAnnotation = false)
Parameters
sentinel
objectThe sentinel value.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionPropertyBuilder
The same builder instance if the configuration was applied, null otherwise.
HasTypeMapping(CoreTypeMapping?, bool)
Configures the CoreTypeMapping for this property.
IConventionPropertyBuilder? HasTypeMapping(CoreTypeMapping? typeMapping, bool fromDataAnnotation = false)
Parameters
typeMapping
CoreTypeMappingThe type mapping, or null to remove any previously set type mapping.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionPropertyBuilder
The same builder instance if the configuration was applied, null otherwise.
HasValueComparer(ValueComparer?, bool)
Configures the ValueComparer for this property.
IConventionPropertyBuilder? HasValueComparer(ValueComparer? comparer, bool fromDataAnnotation = false)
Parameters
comparer
ValueComparerThe comparer, or null to remove any previously set comparer.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionPropertyBuilder
The same builder instance if the configuration was applied, null otherwise.
HasValueComparer(Type?, bool)
Configures the ValueComparer for this property.
IConventionPropertyBuilder? HasValueComparer(Type? comparerType, bool fromDataAnnotation = false)
Parameters
comparerType
TypeA type that derives from ValueComparer, or null to remove any previously set comparer.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionPropertyBuilder
The same builder instance if the configuration was applied, null otherwise.
HasValueGenerator(Func<IProperty, ITypeBase, ValueGenerator>?, bool)
Configures the ValueGenerator that will generate values for this property.
IConventionPropertyBuilder? HasValueGenerator(Func<IProperty, ITypeBase, ValueGenerator>? factory, bool fromDataAnnotation = false)
Parameters
factory
Func<IProperty, ITypeBase, ValueGenerator>A delegate that will be used to create value generator instances.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionPropertyBuilder
The same builder instance if the configuration was applied, null otherwise.
HasValueGenerator(Type?, bool)
Configures the ValueGenerator that will generate values for this property.
IConventionPropertyBuilder? HasValueGenerator(Type? valueGeneratorType, bool fromDataAnnotation = false)
Parameters
valueGeneratorType
TypeA type that inherits from ValueGenerator.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionPropertyBuilder
The same builder instance if the configuration was applied, null otherwise.
HasValueGeneratorFactory(Type?, bool)
Configures the ValueGeneratorFactory for creating a ValueGenerator that will generate values for this property.
IConventionPropertyBuilder? HasValueGeneratorFactory(Type? valueGeneratorFactoryType, bool fromDataAnnotation = false)
Parameters
valueGeneratorFactoryType
TypeA type that inherits from ValueGeneratorFactory.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionPropertyBuilder
The same builder instance if the configuration was applied, null otherwise.
IsConcurrencyToken(bool?, bool)
Configures whether this property should be 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.
IConventionPropertyBuilder? IsConcurrencyToken(bool? concurrencyToken, bool fromDataAnnotation = false)
Parameters
concurrencyToken
bool?A value indicating whether this property is a concurrency token.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionPropertyBuilder
The same builder instance if the configuration was applied, null otherwise.
IsRequired(bool?, bool)
Configures whether this property must have a value assigned or null is a valid value. A property can only be configured as non-required if it is based on a CLR type that can be assigned null.
IConventionPropertyBuilder? IsRequired(bool? required, bool fromDataAnnotation = false)
Parameters
required
bool?A value indicating whether the property is required. null to reset to default.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionPropertyBuilder
The same builder instance if the requiredness was configured, null otherwise.
IsUnicode(bool?, bool)
Configures whether the property as capable of persisting unicode characters.
IConventionPropertyBuilder? IsUnicode(bool? unicode, bool fromDataAnnotation = false)
Parameters
unicode
bool?A value indicating whether the property can contain unicode characters.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionPropertyBuilder
The same builder instance if the configuration was applied, null otherwise.
SetElementType(Type?, bool)
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.
IConventionElementTypeBuilder? SetElementType(Type? elementType, bool fromDataAnnotation = false)
Parameters
Returns
ValueGenerated(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.
IConventionPropertyBuilder? ValueGenerated(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
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionPropertyBuilder
The same builder instance if the requiredness was configured, null otherwise.