PropertyBuilder<TProperty> PropertyBuilder(Of TProperty) Class

Provides a simple API for configuring a Property.

Instances of this class are returned from methods when using the ModelBuilder API and it is not designed to be directly constructed in your application code.

Syntax

Declaration

public class PropertyBuilder<TProperty> : PropertyBuilder, IInfrastructure<IMutableModel>, IInfrastructure<InternalPropertyBuilder>Public Class PropertyBuilder(Of TProperty)
    Inherits PropertyBuilder
    Implements IInfrastructure(Of IMutableModel), IInfrastructure(Of InternalPropertyBuilder)

Type Parameters

TProperty

Inheritance Hierarchy

Inherited Members

IInfrastructure<InternalPropertyBuilder>.Instance,
Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<Microsoft.EntityFrameworkCore.Metadata.Internal.InternalPropertyBuilder>.Instance,
Metadata,
Metadata,
IInfrastructure<IMutableModel>.Instance,
Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<Microsoft.EntityFrameworkCore.Metadata.IMutableModel>.Instance,
ToString(),
ToString(),
Equals(Object),
Equals(Object),
Equals(Object, Object),
Equals(Object, Object),
ReferenceEquals(Object, Object),
ReferenceEquals(Object, Object),
GetHashCode(),
GetHashCode(),
GetType(),
GetType(),
MemberwiseClone()
MemberwiseClone()

Constructors summary

This API supports the Entity Framework Core infrastructure and is not intended to be used directly from your code. This API may change or be removed in future releases.

Methods summary

Adds or updates an annotation on the property. If an annotation with the key specified in annotation already exists it's value will be updated.

Sets the backing field to use for this property.

Backing fields are normally found by convention as described here: http://go.microsoft.com/fwlink/?LinkId=723277. This method is useful for setting backing fields explicitly in cases where the correct field is not found by convention.

By default, the backing field, if one is found or has been specified, is used when new objects are constructed, typically when entities are queried from the database. Properties are used for all other accesses. This can be changed by calling UsePropertyAccessMode(PropertyAccessMode).

Configures the maximum length of data that can be stored in this property. Maximum length can only be set on array properties (including System.String properties).

Configures a factory for creating a ValueGenerator to use to generate values for this property.

Values are generated when the entity is added to the context using, for example, Add<TEntity>(TEntity). Values are generated only when the property is assigned the CLR default value (null for string, 0 for int, Guid.Empty for Guid, etc.).

This factory will be invoked once to create a single instance of the value generator, and this will be used to generate values for this property in all instances of the entity type.

This method is intended for use with custom value generation. Value generation for common cases is usually handled automatically by the database provider.

Configures the ValueGenerator that will generate values for this property.

Values are generated when the entity is added to the context using, for example, Add<TEntity>(TEntity). Values are generated only when the property is assigned the CLR default value (null for string, 0 for int, Guid.Empty for Guid, etc.).

A single instance of this type will be created and used to generate values for this property in all instances of the entity type. The type must be instantiable and have a parameterless constructor.

This method is intended for use with custom value generation. Value generation for common cases is usually handled automatically by the database provider.

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.

Configures the ValueGenerator that will generate values for this property.

Values are generated when the entity is added to the context using, for example, Add<TEntity>(TEntity). Values are generated only when the property is assigned the CLR default value (null for string, 0 for int, Guid.Empty for Guid, etc.).

A single instance of this type will be created and used to generate values for this property in all instances of the entity type. The type must be instantiable and have a parameterless constructor.

This method is intended for use with custom value generation. Value generation for common cases is usually handled automatically by the database provider.

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.

Configures whether this property must have a value assigned or whether 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.

Configures the property as ValueGeneratedOnAddOrUpdate() and IsConcurrencyToken(Boolean).

Database providers can choose to interpret this in different way, but it is commonly used to indicate some form of automatic row-versioning as used for optimistic concurrency detection.

Configures the property as capable of persisting unicode characters or not. Can only be set on System.String properties.

Sets the PropertyAccessMode to use for this property.

By default, the backing field, if one is found by convention or has been specified, is used when new objects are constructed, typically when entities are queried from the database. Properties are used for all other accesses. Calling this method witll change that behavior for this property as described in the PropertyAccessMode enum.

Calling this method overrrides for this property any access mode that was set on the entity type or model.

Configures a property to never have a value generated when an instance of this entity type is saved.

Configures a property to have a value generated only when saving a new entity, unless a non-null, non-temporary value has been set, in which case the set value will be saved instead. The value may be generated by a client-side value generator or may be generated by the database as part of saving the entity.

Configures a property to have a value generated only when saving a new or existing entity, unless a non-null, non-temporary value has been set for a new entity, or the existing property value has been modified for an existing entity, in which case the set value will be saved instead.

Constructors

  • PropertyBuilder(InternalPropertyBuilder)
    PropertyBuilder(InternalPropertyBuilder)

    This API supports the Entity Framework Core infrastructure and is not intended to be used directly from your code. This API may change or be removed in future releases.

    public PropertyBuilder(InternalPropertyBuilder builder)Public Sub New(builder As InternalPropertyBuilder)

    Parameters

Methods

  • HasAnnotation(String, Object)
    HasAnnotation(String, Object)

    Adds or updates an annotation on the property. If an annotation with the key specified in annotation already exists it's value will be updated.

    public virtual PropertyBuilder<TProperty> HasAnnotation(string annotation, object value)Public Overridable Function HasAnnotation(annotation As String, value As Object) As PropertyBuilder(Of TProperty)

    Parameters

    • annotation
      System.String
      System.String

      The key of the annotation to be added or updated.

    • value
      System.Object
      System.Object

      The value to be stored in the annotation.

    Returns

  • HasField(String)
    HasField(String)

    Sets the backing field to use for this property.

    Backing fields are normally found by convention as described here: http://go.microsoft.com/fwlink/?LinkId=723277. This method is useful for setting backing fields explicitly in cases where the correct field is not found by convention.

    By default, the backing field, if one is found or has been specified, is used when new objects are constructed, typically when entities are queried from the database. Properties are used for all other accesses. This can be changed by calling UsePropertyAccessMode(PropertyAccessMode).

    public virtual PropertyBuilder<TProperty> HasField(string fieldName)Public Overridable Function HasField(fieldName As String) As PropertyBuilder(Of TProperty)

    Parameters

    • fieldName
      System.String
      System.String

      The field name.

    Returns

  • HasMaxLength(Int32)
    HasMaxLength(Int32)

    Configures the maximum length of data that can be stored in this property. Maximum length can only be set on array properties (including System.String properties).

    public virtual PropertyBuilder<TProperty> HasMaxLength(int maxLength)Public Overridable Function HasMaxLength(maxLength As Integer) As PropertyBuilder(Of TProperty)

    Parameters

    • maxLength
      System.Int32
      System.Int32

      The maximum length of data allowed in the property.

    Returns

  • HasValueGenerator(Func<IProperty, IEntityType, ValueGenerator>)
    HasValueGenerator(Func(Of IProperty, IEntityType, ValueGenerator))

    Configures a factory for creating a ValueGenerator to use to generate values for this property.

    Values are generated when the entity is added to the context using, for example, Add<TEntity>(TEntity). Values are generated only when the property is assigned the CLR default value (null for string, 0 for int, Guid.Empty for Guid, etc.).

    This factory will be invoked once to create a single instance of the value generator, and this will be used to generate values for this property in all instances of the entity type.

    This method is intended for use with custom value generation. Value generation for common cases is usually handled automatically by the database provider.

    public virtual PropertyBuilder<TProperty> HasValueGenerator(Func<IProperty, IEntityType, ValueGenerator> factory)Public Overridable Function HasValueGenerator(factory As Func(Of IProperty, IEntityType, ValueGenerator)) As PropertyBuilder(Of TProperty)

    Parameters

    Returns

  • HasValueGenerator(Type)
    HasValueGenerator(Type)

    Configures the ValueGenerator that will generate values for this property.

    Values are generated when the entity is added to the context using, for example, Add<TEntity>(TEntity). Values are generated only when the property is assigned the CLR default value (null for string, 0 for int, Guid.Empty for Guid, etc.).

    A single instance of this type will be created and used to generate values for this property in all instances of the entity type. The type must be instantiable and have a parameterless constructor.

    This method is intended for use with custom value generation. Value generation for common cases is usually handled automatically by the database provider.

    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.

    public virtual PropertyBuilder<TProperty> HasValueGenerator(Type valueGeneratorType)Public Overridable Function HasValueGenerator(valueGeneratorType As Type) As PropertyBuilder(Of TProperty)

    Parameters

    • valueGeneratorType
      System.Type
      System.Type

      A type that inherits from ValueGenerator

    Returns

  • HasValueGenerator<TGenerator>()
    HasValueGenerator(Of TGenerator)()

    Configures the ValueGenerator that will generate values for this property.

    Values are generated when the entity is added to the context using, for example, Add<TEntity>(TEntity). Values are generated only when the property is assigned the CLR default value (null for string, 0 for int, Guid.Empty for Guid, etc.).

    A single instance of this type will be created and used to generate values for this property in all instances of the entity type. The type must be instantiable and have a parameterless constructor.

    This method is intended for use with custom value generation. Value generation for common cases is usually handled automatically by the database provider.

    public virtual PropertyBuilder<TProperty> HasValueGenerator<TGenerator>()where TGenerator : ValueGeneratorPublic Overridable Function HasValueGenerator(Of TGenerator As ValueGenerator) As PropertyBuilder(Of TProperty)

    Returns

  • IsConcurrencyToken(Boolean)
    IsConcurrencyToken(Boolean)

    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.

    public virtual PropertyBuilder<TProperty> IsConcurrencyToken(bool concurrencyToken = true)Public Overridable Function IsConcurrencyToken(concurrencyToken As Boolean = True) As PropertyBuilder(Of TProperty)

    Parameters

    • concurrencyToken
      System.Boolean
      System.Boolean

      A value indicating whether this property is a concurrency token.

    Returns

  • IsRequired(Boolean)
    IsRequired(Boolean)

    Configures whether this property must have a value assigned or whether 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.

    public virtual PropertyBuilder<TProperty> IsRequired(bool required = true)Public Overridable Function IsRequired(required As Boolean = True) As PropertyBuilder(Of TProperty)

    Parameters

    • required
      System.Boolean
      System.Boolean

      A value indicating whether the property is required.

    Returns

  • IsRowVersion()
    IsRowVersion()

    Configures the property as ValueGeneratedOnAddOrUpdate() and IsConcurrencyToken(Boolean).

    Database providers can choose to interpret this in different way, but it is commonly used to indicate some form of automatic row-versioning as used for optimistic concurrency detection.

    public virtual PropertyBuilder<TProperty> IsRowVersion()Public Overridable Function IsRowVersion As PropertyBuilder(Of TProperty)

    Returns

  • IsUnicode(Boolean)
    IsUnicode(Boolean)

    Configures the property as capable of persisting unicode characters or not. Can only be set on System.String properties.

    public virtual PropertyBuilder<TProperty> IsUnicode(bool unicode = true)Public Overridable Function IsUnicode(unicode As Boolean = True) As PropertyBuilder(Of TProperty)

    Parameters

    • unicode
      System.Boolean
      System.Boolean

      A value indicating whether the property can contain unicode characters or not.

    Returns

  • UsePropertyAccessMode(PropertyAccessMode)
    UsePropertyAccessMode(PropertyAccessMode)

    Sets the PropertyAccessMode to use for this property.

    By default, the backing field, if one is found by convention or has been specified, is used when new objects are constructed, typically when entities are queried from the database. Properties are used for all other accesses. Calling this method witll change that behavior for this property as described in the PropertyAccessMode enum.

    Calling this method overrrides for this property any access mode that was set on the entity type or model.

    public virtual PropertyBuilder<TProperty> UsePropertyAccessMode(PropertyAccessMode propertyAccessMode)Public Overridable Function UsePropertyAccessMode(propertyAccessMode As PropertyAccessMode) As PropertyBuilder(Of TProperty)

    Parameters

    Returns

  • ValueGeneratedNever()
    ValueGeneratedNever()

    Configures a property to never have a value generated when an instance of this entity type is saved.

    public virtual PropertyBuilder<TProperty> ValueGeneratedNever()Public Overridable Function ValueGeneratedNever As PropertyBuilder(Of TProperty)

    Returns

    Remarks

    Note that temporary values may still be generated for use internally before a new entity is saved.

  • ValueGeneratedOnAdd()
    ValueGeneratedOnAdd()

    Configures a property to have a value generated only when saving a new entity, unless a non-null, non-temporary value has been set, in which case the set value will be saved instead. The value may be generated by a client-side value generator or may be generated by the database as part of saving the entity.

    public virtual PropertyBuilder<TProperty> ValueGeneratedOnAdd()Public Overridable Function ValueGeneratedOnAdd As PropertyBuilder(Of TProperty)

    Returns

  • ValueGeneratedOnAddOrUpdate()
    ValueGeneratedOnAddOrUpdate()

    Configures a property to have a value generated only when saving a new or existing entity, unless a non-null, non-temporary value has been set for a new entity, or the existing property value has been modified for an existing entity, in which case the set value will be saved instead.

    public virtual PropertyBuilder<TProperty> ValueGeneratedOnAddOrUpdate()Public Overridable Function ValueGeneratedOnAddOrUpdate As PropertyBuilder(Of TProperty)

    Returns

Details

Assembly

Microsoft.EntityFrameworkCore.dll