PropertyBuilder.HasValueGenerator Method

Definition

Overloads

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(Type)

Configures the ValueGenerator that will generate values for this property.

HasValueGenerator<TGenerator>()

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.

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

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 HasValueGenerator (Func<Microsoft.EntityFrameworkCore.Metadata.IProperty,Microsoft.EntityFrameworkCore.Metadata.ITypeBase,Microsoft.EntityFrameworkCore.ValueGeneration.ValueGenerator> factory);
abstract member HasValueGenerator : Func<Microsoft.EntityFrameworkCore.Metadata.IProperty, Microsoft.EntityFrameworkCore.Metadata.ITypeBase, Microsoft.EntityFrameworkCore.ValueGeneration.ValueGenerator> -> Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder
override this.HasValueGenerator : Func<Microsoft.EntityFrameworkCore.Metadata.IProperty, Microsoft.EntityFrameworkCore.Metadata.ITypeBase, Microsoft.EntityFrameworkCore.ValueGeneration.ValueGenerator> -> Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder
Public Overridable Function HasValueGenerator (factory As Func(Of IProperty, ITypeBase, ValueGenerator)) As PropertyBuilder

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(Type)

Configures the ValueGenerator that will generate values for this property.

public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder HasValueGenerator (Type valueGeneratorType);
public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder HasValueGenerator (Type? valueGeneratorType);
abstract member HasValueGenerator : Type -> Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder
override this.HasValueGenerator : Type -> Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder
Public Overridable Function HasValueGenerator (valueGeneratorType As Type) As PropertyBuilder

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<TGenerator>()

Configures the ValueGenerator that will generate values for this property.

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

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