PropertyBuilder<TProperty>.HasValueGenerator Method

Definition

Overloads

HasValueGenerator(Type)

Configures the ValueGenerator that will generate values for this property.

HasValueGenerator(Func<IProperty,IEntityType,ValueGenerator>)

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

HasValueGenerator(Func<IProperty,ITypeBase,ValueGenerator>)

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

HasValueGenerator<TGenerator>()

Configures the ValueGenerator that will generate values for this property.

HasValueGenerator(Type)

Configures the ValueGenerator that will generate values for this property.

public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder<TProperty> HasValueGenerator (Type valueGeneratorType);
public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder<TProperty> HasValueGenerator (Type? valueGeneratorType);
override this.HasValueGenerator : Type -> Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder<'Property>
Public Overridable Function HasValueGenerator (valueGeneratorType As Type) As PropertyBuilder(Of TProperty)

Parameters

valueGeneratorType
Type

A type that inherits from ValueGenerator.

Returns

The same builder instance so that multiple configuration calls can be chained.

Remarks

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.

Applies to

HasValueGenerator(Func<IProperty,IEntityType,ValueGenerator>)

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

public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder<TProperty> HasValueGenerator (Func<Microsoft.EntityFrameworkCore.Metadata.IProperty,Microsoft.EntityFrameworkCore.Metadata.IEntityType,Microsoft.EntityFrameworkCore.ValueGeneration.ValueGenerator> factory);
override this.HasValueGenerator : Func<Microsoft.EntityFrameworkCore.Metadata.IProperty, Microsoft.EntityFrameworkCore.Metadata.IEntityType, Microsoft.EntityFrameworkCore.ValueGeneration.ValueGenerator> -> Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder<'Property>
Public Overridable Function HasValueGenerator (factory As Func(Of IProperty, IEntityType, ValueGenerator)) As PropertyBuilder(Of TProperty)

Parameters

factory
Func<IProperty,IEntityType,ValueGenerator>

A delegate that will be used to create value generator instances.

Returns

The same builder instance so that multiple configuration calls can be chained.

Remarks

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.

Applies to

HasValueGenerator(Func<IProperty,ITypeBase,ValueGenerator>)

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

public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder<TProperty> HasValueGenerator (Func<Microsoft.EntityFrameworkCore.Metadata.IProperty,Microsoft.EntityFrameworkCore.Metadata.ITypeBase,Microsoft.EntityFrameworkCore.ValueGeneration.ValueGenerator> factory);
override this.HasValueGenerator : Func<Microsoft.EntityFrameworkCore.Metadata.IProperty, Microsoft.EntityFrameworkCore.Metadata.ITypeBase, Microsoft.EntityFrameworkCore.ValueGeneration.ValueGenerator> -> Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder<'Property>
Public Overridable Function HasValueGenerator (factory As Func(Of IProperty, ITypeBase, ValueGenerator)) As PropertyBuilder(Of TProperty)

Parameters

factory
Func<IProperty,ITypeBase,ValueGenerator>

A delegate that will be used to create value generator instances.

Returns

The same builder instance so that multiple configuration calls can be chained.

Remarks

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.

Applies to

HasValueGenerator<TGenerator>()

Configures the ValueGenerator that will generate values for this property.

public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder<TProperty> HasValueGenerator<TGenerator> () where TGenerator : Microsoft.EntityFrameworkCore.ValueGeneration.ValueGenerator;
override this.HasValueGenerator : unit -> Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder<'Property> (requires 'Generator :> Microsoft.EntityFrameworkCore.ValueGeneration.ValueGenerator)
Public Overridable Function HasValueGenerator(Of TGenerator As ValueGenerator) () As PropertyBuilder(Of TProperty)

Type Parameters

TGenerator

A type that inherits from ValueGenerator.

Returns

The same builder instance so that multiple configuration calls can be chained.

Remarks

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.

Applies to