Skip to main content
Version: Preview (0.3.0-preview.205)

Class ValueObjectConventionExtensions

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

Maps value objects onto their underlying database types.

public static class ValueObjectConventionExtensions

Inheritance​

object ← ValueObjectConventionExtensions

Inherited Members​

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Methods​

ConfigureValueObjects(ModelConfigurationBuilder, params Assembly[])​

Maps every value object declared in the given assemblies to its underlying column type.

public static ModelConfigurationBuilder ConfigureValueObjects(this ModelConfigurationBuilder builder, params Assembly[] assemblies)

Parameters​

builder ModelConfigurationBuilder

Model configuration builder, from DbContext.ConfigureConventions.

assemblies Assembly[]

Assemblies declaring the value objects. When none is given, everything already registered is mapped, which is enough as soon as the entity assembly has been loaded.

Returns​

ModelConfigurationBuilder

The same builder, so calls can be chained.

Remarks​

A value object declaring a maximum length also sizes its column, so an IBAN lands in varchar(34) rather than an unbounded column — the rule is stated once, on the type, and the schema follows.

A value object over or is left alone: Entity Framework Core maps neither type, on any provider, so the column type, and the conversion to it, are the application's to choose with a converter of its own.

A generic value object, Code<T> or Outer<T>.Code, is mapped too, whatever its constructions: each property of one gets the converter, the comparer and the length closed over its own.

This runs once, while the model is built. Nothing here happens per query or per row.

ConfigureValueObjects(ModelConfigurationBuilder, bool, params Assembly[])​

Maps every value object declared in the given assemblies, optionally re-validating on read.

public static ModelConfigurationBuilder ConfigureValueObjects(this ModelConfigurationBuilder builder, bool strict, params Assembly[] assemblies)

Parameters​

builder ModelConfigurationBuilder

Model configuration builder, from DbContext.ConfigureConventions.

strict bool

When true, values read from the database are normalized and validated again. Use it for tables another system also writes to; it costs a validation per materialized value.

assemblies Assembly[]

Assemblies declaring the value objects.

Returns​

ModelConfigurationBuilder

The same builder, so calls can be chained.

HasValueObjectConversion<TSelf, TValue>(PropertyBuilder<TSelf>, bool)​

Maps a single property to the underlying value of its value object.

public static PropertyBuilder<TSelf> HasValueObjectConversion<TSelf, TValue>(this PropertyBuilder<TSelf> builder, bool strict = false) where TSelf : struct, IValueObject<TSelf, TValue>

Parameters​

builder PropertyBuilder<TSelf>

Property builder.

strict bool

When true, values read from the database are validated again.

Returns​

PropertyBuilder<TSelf>

The same builder, so calls can be chained.

Type Parameters​

TSelf

Value object type.

TValue

Underlying value type.

Remarks​

Use this for a property that needs to depart from the convention; otherwise prefer the convention. It cannot map a value object over or , which Entity Framework Core maps to no column: such a property needs a converter of the application's own.