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
configurationBuilderModelConfigurationBuilderThe model configuration builder.
compositesIEnumerable<Type>Composite Trellis
ValueObjecttypes.
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
configurationBuilderModelConfigurationBuilderThe model configuration builder.
Returns
- ModelConfigurationBuilder
The same ModelConfigurationBuilder for chaining.
Type Parameters
TClrThe Trellis scalar value object CLR type (e.g.
CustomerId).TProviderThe 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
configurationBuilderModelConfigurationBuilderThe model configuration builder.
assembliesAssembly[]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
configurationBuilderModelConfigurationBuilderThe model configuration builder.
scalarsIEnumerable<(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))).compositesIEnumerable<Type>Composite (non-scalar) Trellis
ValueObjecttypes to register withCompositeValueObjectConvention.
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).