PrimitiveCollectionBuilder<TProperty>.HasValueGenerator Method

Definition

Overloads

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

Source:
PrimitiveCollectionBuilder%60.cs
Source:
PrimitiveCollectionBuilder%60.cs

Configures the ValueGenerator that will generate values for this property.

C#
public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.PrimitiveCollectionBuilder<TProperty> HasValueGenerator (Type? valueGeneratorType);

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

Entity Framework Core 9.0 и Entity Framework Core 8.0
Продукт Версии
Entity Framework Core 8.0, 9.0

HasValueGenerator<TGenerator>()

Source:
PrimitiveCollectionBuilder%60.cs
Source:
PrimitiveCollectionBuilder%60.cs

Configures the ValueGenerator that will generate values for this property.

C#
public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.PrimitiveCollectionBuilder<TProperty> HasValueGenerator<TGenerator> () where TGenerator : Microsoft.EntityFrameworkCore.ValueGeneration.ValueGenerator;

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

Entity Framework Core 9.0 и Entity Framework Core 8.0
Продукт Версии
Entity Framework Core 8.0, 9.0