Skip to main content
Version: 0.3.x (0.3.0)

Class ValueObjectKeyGeneratorFactory<TSelf, TValue>

Namespace: AdCodicem.ValueObjects.EntityFrameworkCore
Assembly: AdCodicem.ValueObjects.EntityFrameworkCore.dll

Creates the generator HasValueObjectKeyGeneration gives a key, by a type a compiled model can instantiate: GUIDs a database keeps in order for a key over , and the temporary values Entity Framework Core holds until the database generates a key over an integer.

public sealed class ValueObjectKeyGeneratorFactory<TSelf, TValue> : ValueGeneratorFactory where TSelf : struct, IValueObject<TSelf, TValue>

Type Parameters​

TSelf

Value object type.

TValue

Underlying value type: , , or , the types HasValueObjectKeyGeneration is declared for.

Inheritance​

object ← ValueGeneratorFactory ← ValueObjectKeyGeneratorFactory<TSelf, TValue>

Inherited Members​

ValueGeneratorFactory.Create(IProperty, ITypeBase), object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Remarks​

A GUID is SQL Server's sequential one on SQL Server (), as Entity Framework Core generates for a key there, which SQL Server sorts in the order it was generated, and a version 7 one on every other provider, as Npgsql generates for PostgreSQL, where Entity Framework Core would generate random ones on SQLite and elsewhere. The value object is created from it through Create, so a rule the GUID breaks fails the add with the value object's rather than reach the column.

An integer is a temporary value, negative, which the change tracker holds until SaveChanges, when the database's identity takes its place. It is never written, so it is created unchecked, and a type counted from one accepts it, a strict context included; the key the database hands back is read through the converter. Only a relational database generates it: on another provider, Entity Framework Core's in-memory database for one, the add fails with an rather than store the temporary value as the key.

HasValueObjectKeyGeneration sets it on the property, and a compiled model writes it as new ValueObjectKeyGeneratorFactory<TSelf, TValue>().Create.

Methods​

Create(IProperty, ITypeBase)​

Creates a new value generator.

public override ValueGenerator Create(IProperty property, ITypeBase typeBase)

Parameters​

property IProperty

The property to create the value generator for.

typeBase ITypeBase

The type for which the value generator will be used.

Returns​

ValueGenerator

The newly created value generator.

Remarks​

See EF Core value generation for more information and examples.