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

Class EntityIdConventionExtensions

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

Maps entity identifiers onto the narrowest column that can hold them.

public static class EntityIdConventionExtensions

Inheritance​

object ← EntityIdConventionExtensions

Inherited Members​

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

Remarks​

An identifier is a value object, so ConfigureValueObjects already maps it. What this adds is everything that follows from the identifier being fixed-width and ASCII: char(n) rather than varchar(n), non-Unicode so a SQL Server column is not silently doubled to nchar, and optionally a binary collation.

It also applies the conversion itself, so a model holding nothing but identifiers needs this call alone. Calling both is fine, given the same strictness: whichever call runs last sets the converter of the identifiers, so a context reading through ConfigureValueObjects(strict: true) passes strict: true here too, or its identifiers are read without validation.

What it deliberately does not do is decide the physical layout of your tables. On SQL Server a primary key is clustered by default, which makes the table itself order by the key; declaring it IsClustered(false) confines index churn to the ~30-byte index instead of the whole row, and with the monotonic time bucket at the head of the body the fill factor can go back up towards 95. Those are choices about your schema, not about the identifier type, and they need the provider-specific packages.

Methods​

ConfigureEntityIds(ModelConfigurationBuilder, params Assembly[])​

Maps every registered entity identifier to a fixed-width column.

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

Parameters​

builder ModelConfigurationBuilder

Model configuration builder, from DbContext.ConfigureConventions.

assemblies Assembly[]

Assemblies declaring the identifiers. 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.

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

Maps every registered entity identifier to a fixed-width column, optionally validating what is read.

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

Parameters​

builder ModelConfigurationBuilder

Model configuration builder, from DbContext.ConfigureConventions.

strict bool

When true, identifiers read from the database are normalized and validated again, as ConfigureValueObjects(strict: true) does for the other value objects.

assemblies Assembly[]

Assemblies declaring the identifiers.

Returns​

ModelConfigurationBuilder

The same builder, so calls can be chained.

ConfigureEntityIds(ModelConfigurationBuilder, string?, params Assembly[])​

Maps every registered entity identifier to a fixed-width column with an explicit collation.

public static ModelConfigurationBuilder ConfigureEntityIds(this ModelConfigurationBuilder builder, string? collation, params Assembly[] assemblies)

Parameters​

builder ModelConfigurationBuilder

Model configuration builder, from DbContext.ConfigureConventions.

collation string?

Collation for the identifier columns, or null to leave the database default in place. names the binary one per provider.

assemblies Assembly[]

Assemblies declaring the identifiers.

Returns​

ModelConfigurationBuilder

The same builder, so calls can be chained.

Examples​

protected override void ConfigureConventions(ModelConfigurationBuilder builder)
=> builder.ConfigureEntityIds(IdCollations.PostgreSql, typeof(AccountId).Assembly);

ConfigureEntityIds(ModelConfigurationBuilder, string?, bool, params Assembly[])​

Maps every registered entity identifier to a fixed-width column with an explicit collation, optionally validating what is read.

public static ModelConfigurationBuilder ConfigureEntityIds(this ModelConfigurationBuilder builder, string? collation, bool strict, params Assembly[] assemblies)

Parameters​

builder ModelConfigurationBuilder

Model configuration builder, from DbContext.ConfigureConventions.

collation string?

Collation for the identifier columns, or null to leave the database default in place. names the binary one per provider.

strict bool

When true, identifiers read from the database are normalized and validated again, as ConfigureValueObjects(strict: true) does for the other value objects. A value the identifier refuses fails the query with a .

assemblies Assembly[]

Assemblies declaring the identifiers.

Returns​

ModelConfigurationBuilder

The same builder, so calls can be chained.

HasEntityIdConversion<TId>(PropertyBuilder<TId>, string?)​

Maps a single property holding an entity identifier.

public static PropertyBuilder<TId> HasEntityIdConversion<TId>(this PropertyBuilder<TId> builder, string? collation = null) where TId : struct, IEntityId<TId>

Parameters​

builder PropertyBuilder<TId>

Property builder.

collation string?

Collation for the column, or null for the database default.

Returns​

PropertyBuilder<TId>

The same builder, so calls can be chained.

Type Parameters​

TId

Identifier type.

Remarks​

Use this for a property that needs to depart from the convention; otherwise prefer the convention.

HasEntityIdConversion<TId>(PropertyBuilder<TId>, bool)​

Maps a single property holding an entity identifier, validating what is read from the database or not.

public static PropertyBuilder<TId> HasEntityIdConversion<TId>(this PropertyBuilder<TId> builder, bool strict) where TId : struct, IEntityId<TId>

Parameters​

builder PropertyBuilder<TId>

Property builder.

strict bool

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

Returns​

PropertyBuilder<TId>

The same builder, so calls can be chained.

Type Parameters​

TId

Identifier type.

Remarks​

Use this for a property that needs to depart from the convention; otherwise prefer the convention.

HasEntityIdConversion<TId>(PropertyBuilder<TId>, string?, bool)​

Maps a single property holding an entity identifier, with a collation, validating what is read from the database or not.

public static PropertyBuilder<TId> HasEntityIdConversion<TId>(this PropertyBuilder<TId> builder, string? collation, bool strict) where TId : struct, IEntityId<TId>

Parameters​

builder PropertyBuilder<TId>

Property builder.

collation string?

Collation for the column, or null for the database default.

strict bool

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

Returns​

PropertyBuilder<TId>

The same builder, so calls can be chained.

Type Parameters​

TId

Identifier type.

Remarks​

Use this for a property that needs to depart from the convention; otherwise prefer the convention. Pass the same strict as to the convention, which a property configured here otherwise departs from.