Table of Contents

Class ModelConfigurationBuilderExtensions

Namespace
Trellis.EntityFrameworkCore
Assembly
Trellis.EntityFrameworkCore.dll

Extension methods for ModelConfigurationBuilder that register Trellis value object conventions before EF Core model building.

public static class ModelConfigurationBuilderExtensions
Inheritance
ModelConfigurationBuilderExtensions
Inherited Members

Methods

AddTrellisCoreConventions(ModelConfigurationBuilder, IEnumerable<Type>)

Adds the fixed Trellis EF Core conventions: MaybeConvention, CompositeValueObjectConvention, MoneyConvention, AggregateETagConvention, AggregateTransientPropertyConvention, and ValueObjectMappingGuardConvention.

public static ModelConfigurationBuilder AddTrellisCoreConventions(this ModelConfigurationBuilder configurationBuilder, IEnumerable<Type> composites)

Parameters

configurationBuilder ModelConfigurationBuilder

The model configuration builder.

composites IEnumerable<Type>

Composite Trellis ValueObject types.

Returns

ModelConfigurationBuilder

The same ModelConfigurationBuilder for chaining.

Remarks

Reflection-free: no calls to MakeGenericType(params Type[]). The composites argument carries already-closed Type tokens supplied by the caller (typically the source generator).

AddTrellisScalarConverter<TClr, TProvider>(ModelConfigurationBuilder)

Registers a strongly-typed TrellisScalarConverter<TModel, TProvider> for TClr properties that round-trip to TProvider.

public static ModelConfigurationBuilder AddTrellisScalarConverter<TClr, TProvider>(this ModelConfigurationBuilder configurationBuilder) where TClr : class where TProvider : notnull

Parameters

configurationBuilder ModelConfigurationBuilder

The model configuration builder.

Returns

ModelConfigurationBuilder

The same ModelConfigurationBuilder for chaining.

Type Parameters

TClr

The Trellis scalar value object CLR type (e.g. CustomerId).

TProvider

The provider primitive type (e.g. Guid, string).

Remarks

Reflection-free: no calls to MakeGenericType(params Type[]) or other runtime reflection. Intended for source-generated convention registration.

ApplyTrellisConventions(ModelConfigurationBuilder, params Assembly[])

Registers pre-convention value converters for all Trellis value object types found in the specified assemblies plus the built-in Trellis.Primitives assembly.

This tells EF Core to treat Trellis value objects as scalar properties before convention processing runs, eliminating the need for inline HasConversion() calls in OnModelCreating.

protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
    // Scans your assembly for CustomerId, OrderStatus, etc.
    // Also auto-scans Trellis.Primitives for EmailAddress, Url, PhoneNumber, etc.
    configurationBuilder.ApplyTrellisConventions(typeof(CustomerId).Assembly);
}
public static ModelConfigurationBuilder ApplyTrellisConventions(this ModelConfigurationBuilder configurationBuilder, params Assembly[] assemblies)

Parameters

configurationBuilder ModelConfigurationBuilder

The model configuration builder.

assemblies Assembly[]

Assemblies containing Trellis value object types to register. The Trellis.Primitives assembly (containing EmailAddress, Url, etc.) is always included automatically.

Returns

ModelConfigurationBuilder

The same ModelConfigurationBuilder for chaining.

ApplyTrellisConventionsCore(ModelConfigurationBuilder, IEnumerable<(Type ClrType, Type ProviderType)>, IEnumerable<Type>)

Low-level convention-registration helper used by both the reflection-based ApplyTrellisConventions(ModelConfigurationBuilder, params Assembly[]) overload and the source-generated ApplyTrellisConventionsFor<TContext> entry point.

public static ModelConfigurationBuilder ApplyTrellisConventionsCore(this ModelConfigurationBuilder configurationBuilder, IEnumerable<(Type ClrType, Type ProviderType)> scalars, IEnumerable<Type> composites)

Parameters

configurationBuilder ModelConfigurationBuilder

The model configuration builder.

scalars IEnumerable<(Type ClrType, Type ProviderType)>

Scalar Trellis value object types, each paired with the EF Core provider primitive type that the converter should round-trip to (e.g. (typeof(CustomerId), typeof(Guid))).

composites IEnumerable<Type>

Composite (non-scalar) Trellis ValueObject types to register with CompositeValueObjectConvention.

Returns

ModelConfigurationBuilder

The same ModelConfigurationBuilder for chaining.

Remarks

Most users should call ApplyTrellisConventions(ModelConfigurationBuilder, params Assembly[]) or the generated ApplyTrellisConventionsFor<TContext> extension instead. This method is exposed for source generators that have already classified Trellis value object types at compile time.

Registers a TrellisScalarConverter<TModel, TProvider> for each scalar entry, then adds the fixed Trellis conventions (MaybeConvention, CompositeValueObjectConvention, MoneyConvention, AggregateETagConvention, AggregateTransientPropertyConvention, ValueObjectMappingGuardConvention).