Table of Contents

Class EntityMetadataBuilder<T>

Namespace
NextORM.Core
Assembly
nextorm.core.dll

Fluent builder, passed to From<T>(...), that declares the table name and column mappings of an entity type.

public class EntityMetadataBuilder<T>

Type Parameters

T
Inheritance
EntityMetadataBuilder<T>
Inherited Members
Extension Methods

Methods

AutoBuild()

Builds the metadata entirely by reflecting over the CLR type, ignoring any table or property mappings declared on this builder. Attribute-declared relationships are still read (they are part of the CLR type); fluent relationship declarations are not.

public IEntityMetadata AutoBuild()

Returns

IEntityMetadata

The auto-derived entity metadata.

Build()

Builds the metadata from the mappings declared on this builder, auto-deriving the table name and, when no properties were declared, the property mappings from the CLR type. Declaring even one property fluently maps only the declared properties: the CLR attributes on the other properties are not auto-built (they would otherwise need merging with the fluent overrides).

public IEntityMetadata Build()

Returns

IEntityMetadata

The resolved entity metadata.

HasManyThrough<TChild, TJunction>(Expression<Func<T, IEnumerable<TChild>>>, Expression<Func<T, object?>>, Expression<Func<TJunction, object?>>, Expression<Func<TChild, object?>>, Expression<Func<TJunction, object?>>)

Declares a many-to-many relationship with explicit key components on both legs: a collection navigation on this entity, the parent-side key on this entity, the junction foreign key that references it, the child-side key on the related type and the junction foreign key that references that. Each pair must have the same number of components and matching positional types.

public EntityMetadataBuilder<T> HasManyThrough<TChild, TJunction>(Expression<Func<T, IEnumerable<TChild>>> navigation, Expression<Func<T, object?>> parentKey, Expression<Func<TJunction, object?>> junctionParentForeignKey, Expression<Func<TChild, object?>> childKey, Expression<Func<TJunction, object?>> junctionChildForeignKey) where TChild : class where TJunction : class

Parameters

navigation Expression<Func<T, IEnumerable<TChild>>>

Selects the collection navigation on this entity, for example p => p.Children.

parentKey Expression<Func<T, object>>

Selects the parent-side key components on this entity.

junctionParentForeignKey Expression<Func<TJunction, object>>

Selects the junction components that reference parentKey.

childKey Expression<Func<TChild, object>>

Selects the child-side key components on TChild.

junctionChildForeignKey Expression<Func<TJunction, object>>

Selects the junction components that reference childKey.

Returns

EntityMetadataBuilder<T>

This builder, for chaining.

Type Parameters

TChild

The child entity type.

TJunction

The junction (link) entity type.

Exceptions

ArgumentNullException

A selector is null.

NotSupportedException

A selector is not a supported key selector, the navigation is not a collection of TChild, or a key leg does not match its junction foreign key's arity or types.

HasManyThrough<TChild, TJunction>(Expression<Func<T, IEnumerable<TChild>>>, Expression<Func<TJunction, object?>>, Expression<Func<TJunction, object?>>)

Declares a many-to-many relationship with the default full principal keys on both sides: a collection navigation on this entity, the junction foreign key that references this entity's full key and the junction foreign key that references the related type's full key. Both keys are taken from entity metadata in property order.

public EntityMetadataBuilder<T> HasManyThrough<TChild, TJunction>(Expression<Func<T, IEnumerable<TChild>>> navigation, Expression<Func<TJunction, object?>> junctionParentForeignKey, Expression<Func<TJunction, object?>> junctionChildForeignKey) where TChild : class where TJunction : class

Parameters

navigation Expression<Func<T, IEnumerable<TChild>>>

Selects the collection navigation on this entity, for example p => p.Children.

junctionParentForeignKey Expression<Func<TJunction, object>>

Selects the junction components that reference this entity's key.

junctionChildForeignKey Expression<Func<TJunction, object>>

Selects the junction components that reference the related type's key.

Returns

EntityMetadataBuilder<T>

This builder, for chaining.

Type Parameters

TChild

The child entity type.

TJunction

The junction (link) entity type.

Exceptions

ArgumentNullException

A selector is null.

NotSupportedException

A selector is not a supported key selector, the navigation is not a collection of TChild, or a default key's arity does not match its junction foreign key.

HasManyThrough<TChild, TJunction, TParentKey, TChildKey>(Expression<Func<T, IEnumerable<TChild>>>, Expression<Func<T, TParentKey>>, Expression<Func<TJunction, TParentKey>>, Expression<Func<TChild, TChildKey>>, Expression<Func<TJunction, TChildKey>>)

Declares a many-to-many relationship: a collection navigation on this entity, the keys on both principal sides and the junction (link) entity's foreign keys that reference them. The junction is explicit; the core does not infer it. The navigation participates in a declared relationship and is excluded from Properties. The keys are resolved lazily, so the junction and the child type may be registered later.

public EntityMetadataBuilder<T> HasManyThrough<TChild, TJunction, TParentKey, TChildKey>(Expression<Func<T, IEnumerable<TChild>>> navigation, Expression<Func<T, TParentKey>> parentKey, Expression<Func<TJunction, TParentKey>> junctionParentForeignKey, Expression<Func<TChild, TChildKey>> childKey, Expression<Func<TJunction, TChildKey>> junctionChildForeignKey) where TChild : class where TJunction : class

Parameters

navigation Expression<Func<T, IEnumerable<TChild>>>

Selects the collection navigation on this entity, for example p => p.Children.

parentKey Expression<Func<T, TParentKey>>

Selects the parent-side key property on this entity, for example p => p.Id.

junctionParentForeignKey Expression<Func<TJunction, TParentKey>>

Selects the junction foreign key referencing the parent key, for example l => l.ParentId.

childKey Expression<Func<TChild, TChildKey>>

Selects the child-side key property, for example c => c.Id.

junctionChildForeignKey Expression<Func<TJunction, TChildKey>>

Selects the junction foreign key referencing the child key, for example l => l.ChildId.

Returns

EntityMetadataBuilder<T>

This builder, for chaining.

Type Parameters

TChild

The child entity type.

TJunction

The junction (link) entity type.

TParentKey

The property type shared by the parent key and the junction parent foreign key.

TChildKey

The property type shared by the child key and the junction child foreign key.

Exceptions

ArgumentNullException

A selector is null.

NotSupportedException

A selector does not select a property, the navigation is not a collection of TChild, or a key does not match its junction foreign key's type.

HasMany<TChild>(Expression<Func<T, ICollection<TChild>>>, Expression<Func<TChild, object?>>, Expression<Func<T, object?>>)

Declares a one-to-many relationship with an explicit principal key: a collection navigation on this entity, the foreign-key components on the dependent type and the principal-key components on this entity.

public EntityMetadataBuilder<T> HasMany<TChild>(Expression<Func<T, ICollection<TChild>>> navigation, Expression<Func<TChild, object?>> foreignKey, Expression<Func<T, object?>> principalKey) where TChild : class

Parameters

navigation Expression<Func<T, ICollection<TChild>>>

Selects the collection navigation on this entity, for example p => p.Children.

foreignKey Expression<Func<TChild, object>>

Selects the foreign-key components on TChild, for example c => new { c.TenantId, c.ParentId }.

principalKey Expression<Func<T, object>>

Selects the principal-key components on this entity, for example p => new { p.TenantId, p.Id }.

Returns

EntityMetadataBuilder<T>

This builder, for chaining.

Type Parameters

TChild

The dependent entity type.

Exceptions

ArgumentNullException

A selector is null.

NotSupportedException

A selector is not a supported key selector, or the navigation is not a collection of TChild.

HasMany<TChild>(Expression<Func<TChild, object?>>)

Declares a one-to-many relationship without a navigation, a foreign key and the default principal key: the principal key is the full key of this entity, in entity-metadata order.

public EntityMetadataBuilder<T> HasMany<TChild>(Expression<Func<TChild, object?>> foreignKey) where TChild : class

Parameters

foreignKey Expression<Func<TChild, object>>

Selects the foreign-key components on TChild.

Returns

EntityMetadataBuilder<T>

This builder, for chaining.

Type Parameters

TChild

The dependent entity type.

Exceptions

ArgumentNullException

foreignKey is null.

NotSupportedException

The selector is not a supported key selector, or its arity does not match the full principal key.

HasMany<TChild>(Expression<Func<TChild, object?>>, Expression<Func<T, object?>>)

Declares a one-to-many relationship without a navigation and with an explicit principal key: the foreign-key components are selected on the dependent type and the principal-key components on this entity.

public EntityMetadataBuilder<T> HasMany<TChild>(Expression<Func<TChild, object?>> foreignKey, Expression<Func<T, object?>> principalKey) where TChild : class

Parameters

foreignKey Expression<Func<TChild, object>>

Selects the foreign-key components on TChild.

principalKey Expression<Func<T, object>>

Selects the principal-key components on this entity.

Returns

EntityMetadataBuilder<T>

This builder, for chaining.

Type Parameters

TChild

The dependent entity type.

Exceptions

ArgumentNullException

A selector is null.

NotSupportedException

A selector is not a supported key selector.

HasMany<TChild, TKey>(Expression<Func<T, ICollection<TChild>>>, Expression<Func<TChild, TKey>>)

Declares the principal side of a one-to-many relationship: a collection navigation on this entity and the foreign-key property on the related (dependent) type. The principal key is taken from this entity's key metadata; it is resolved lazily and must exist by the time the keys are read. The selector may select a scalar property or a flat anonymous object; the components keep the selector order.

public EntityMetadataBuilder<T> HasMany<TChild, TKey>(Expression<Func<T, ICollection<TChild>>> navigation, Expression<Func<TChild, TKey>> foreignKey) where TChild : class

Parameters

navigation Expression<Func<T, ICollection<TChild>>>

Selects the collection navigation on this entity, for example p => p.Children.

foreignKey Expression<Func<TChild, TKey>>

Selects the foreign-key property on TChild, for example c => c.ParentId.

Returns

EntityMetadataBuilder<T>

This builder, for chaining.

Type Parameters

TChild

The dependent entity type.

TKey

The property type shared by the foreign key and the principal key.

Exceptions

ArgumentNullException

A selector is null.

NotSupportedException

A selector does not select a property, or the navigation is not a collection of TChild.

HasMany<TChild, TKey>(Expression<Func<TChild, TKey>>, Expression<Func<T, TKey>>)

Declares the principal side of a one-to-many relationship for an entity whose navigation is not modelled as a property: the foreign key is selected on the dependent type and the principal key on this entity, and no navigation is attached.

public EntityMetadataBuilder<T> HasMany<TChild, TKey>(Expression<Func<TChild, TKey>> foreignKey, Expression<Func<T, TKey>> principalKey) where TChild : class

Parameters

foreignKey Expression<Func<TChild, TKey>>

Selects the foreign-key property on TChild, for example c => c.ParentId.

principalKey Expression<Func<T, TKey>>

Selects the principal-key property on this entity, for example p => p.Id.

Returns

EntityMetadataBuilder<T>

This builder, for chaining.

Type Parameters

TChild

The dependent entity type.

TKey

The property type shared by the foreign key and the principal key.

Exceptions

ArgumentNullException

A selector is null.

NotSupportedException

A selector does not select a property.

HasOneToOne<TChild>(Expression<Func<T, TChild?>>, Expression<Func<T, object?>>, Expression<Func<TChild, object?>>)

Declares a one-to-one relationship with explicit key components: a reference navigation on this (principal) entity, the principal-key components on this entity and the foreign-key components on the related (dependent) type. Uniqueness of the foreign key remains a declaration-time trust; the core does not inspect the schema.

public EntityMetadataBuilder<T> HasOneToOne<TChild>(Expression<Func<T, TChild?>> navigation, Expression<Func<T, object?>> parentKey, Expression<Func<TChild, object?>> childForeignKey) where TChild : class

Parameters

navigation Expression<Func<T, TChild>>

Selects the reference navigation on this entity, for example p => p.Profile.

parentKey Expression<Func<T, object>>

Selects the principal-key components on this entity, for example p => new { p.TenantId, p.Id }.

childForeignKey Expression<Func<TChild, object>>

Selects the foreign-key components on TChild, for example c => new { c.TenantId, c.OwnerId }.

Returns

EntityMetadataBuilder<T>

This builder, for chaining.

Type Parameters

TChild

The related (dependent) entity type.

Exceptions

ArgumentNullException

A selector is null.

NotSupportedException

A selector is not a supported key selector, or the navigation is a value type or string.

HasOneToOne<TChild, TKey>(Expression<Func<T, TChild?>>, Expression<Func<T, TKey>>, Expression<Func<TChild, TKey>>)

Declares a one-to-one relationship: a reference navigation on this (principal) entity, the principal key on this entity and the unique foreign key on the related (dependent) type. The uniqueness of the foreign key is a declaration-time trust: the core neither inspects the schema or the data nor imposes a uniqueness constraint, so a non-unique foreign key is accepted when the metadata is built. The only runtime guard is per parent through JoinInto: two distinct non-null child identities for one parent throw InvalidOperationException, while repeated identical rows and keyless/null-identity repeats are tolerated (the first child wins). This is the principal counterpart of the HasOne overload, whose foreign key lives on the declaring type.

public EntityMetadataBuilder<T> HasOneToOne<TChild, TKey>(Expression<Func<T, TChild?>> navigation, Expression<Func<T, TKey>> parentKey, Expression<Func<TChild, TKey>> childForeignKey) where TChild : class

Parameters

navigation Expression<Func<T, TChild>>

Selects the reference navigation on this entity, for example p => p.Profile.

parentKey Expression<Func<T, TKey>>

Selects the principal-key property on this entity, for example p => p.Id.

childForeignKey Expression<Func<TChild, TKey>>

Selects the foreign-key property on TChild, for example c => c.ParentId.

Returns

EntityMetadataBuilder<T>

This builder, for chaining.

Type Parameters

TChild

The related (dependent) entity type.

TKey

The property type shared by the principal key and the foreign key.

Exceptions

ArgumentNullException

A selector is null.

NotSupportedException

A selector does not select a property, or the navigation is a value type or string.

HasOneToOne<TChild, TKey>(Expression<Func<T, TChild?>>, Expression<Func<TChild, TKey>>)

Declares a one-to-one relationship without an explicit principal key: a reference navigation on this (principal) entity and the foreign-key components on the related (dependent) type. The principal key is the full key of this entity, in entity-metadata order.

public EntityMetadataBuilder<T> HasOneToOne<TChild, TKey>(Expression<Func<T, TChild?>> navigation, Expression<Func<TChild, TKey>> childForeignKey) where TChild : class

Parameters

navigation Expression<Func<T, TChild>>

Selects the reference navigation on this entity, for example p => p.Profile.

childForeignKey Expression<Func<TChild, TKey>>

Selects the foreign-key component(s) on TChild, for example c => new { c.TenantId, c.OwnerId }.

Returns

EntityMetadataBuilder<T>

This builder, for chaining.

Type Parameters

TChild

The related (dependent) entity type.

TKey

The property type of the child foreign key.

Exceptions

ArgumentNullException

A selector is null.

NotSupportedException

A selector is not a supported key selector, or the navigation is a value type or string.

HasOne<TChild>(Expression<Func<T, object?>>)

Declares a many-to-one relationship without a navigation, a foreign key and the default principal key: the principal key is the full key of TChild, in entity-metadata order.

public EntityMetadataBuilder<T> HasOne<TChild>(Expression<Func<T, object?>> foreignKey) where TChild : class

Parameters

foreignKey Expression<Func<T, object>>

Selects the foreign-key components on this entity.

Returns

EntityMetadataBuilder<T>

This builder, for chaining.

Type Parameters

TChild

The principal entity type.

Exceptions

ArgumentNullException

foreignKey is null.

NotSupportedException

The selector is not a supported key selector, or its arity does not match the full principal key.

HasOne<TChild>(Expression<Func<T, object?>>, Expression<Func<TChild, object?>>)

Declares a many-to-one relationship without a navigation and with an explicit principal key: the foreign-key components are selected on this entity and the principal-key components on the related (principal) type.

public EntityMetadataBuilder<T> HasOne<TChild>(Expression<Func<T, object?>> foreignKey, Expression<Func<TChild, object?>> principalKey) where TChild : class

Parameters

foreignKey Expression<Func<T, object>>

Selects the foreign-key components on this entity.

principalKey Expression<Func<TChild, object>>

Selects the principal-key components on TChild.

Returns

EntityMetadataBuilder<T>

This builder, for chaining.

Type Parameters

TChild

The principal entity type.

Exceptions

ArgumentNullException

A selector is null.

NotSupportedException

A selector is not a supported key selector.

HasOne<TChild>(Expression<Func<T, TChild?>>, Expression<Func<T, object?>>, Expression<Func<TChild, object?>>)

Declares a many-to-one relationship with an explicit principal key: a reference navigation on this entity, the foreign-key components on this entity and the principal-key components on the related (principal) type.

public EntityMetadataBuilder<T> HasOne<TChild>(Expression<Func<T, TChild?>> navigation, Expression<Func<T, object?>> foreignKey, Expression<Func<TChild, object?>> principalKey) where TChild : class

Parameters

navigation Expression<Func<T, TChild>>

Selects the reference navigation on this entity, for example c => c.Parent.

foreignKey Expression<Func<T, object>>

Selects the foreign-key components on this entity, for example c => new { c.TenantId, c.ParentId }.

principalKey Expression<Func<TChild, object>>

Selects the principal-key components on TChild, for example p => new { p.TenantId, p.Id }.

Returns

EntityMetadataBuilder<T>

This builder, for chaining.

Type Parameters

TChild

The principal entity type.

Exceptions

ArgumentNullException

A selector is null.

NotSupportedException

A selector is not a supported key selector, or the navigation is a value type or string.

HasOne<TChild, TKey>(Expression<Func<T, TChild?>>, Expression<Func<T, TKey>>)

Declares the dependent side of a many-to-one relationship: a reference navigation on this entity and the foreign-key property on this same entity. The principal key is taken from the related entity's key metadata; it is resolved lazily and must exist by the time the keys are read.

public EntityMetadataBuilder<T> HasOne<TChild, TKey>(Expression<Func<T, TChild?>> navigation, Expression<Func<T, TKey>> foreignKey) where TChild : class

Parameters

navigation Expression<Func<T, TChild>>

Selects the reference navigation on this entity, for example c => c.Parent.

foreignKey Expression<Func<T, TKey>>

Selects the foreign-key property on this entity, for example c => c.ParentId.

Returns

EntityMetadataBuilder<T>

This builder, for chaining.

Type Parameters

TChild

The principal entity type.

TKey

The property type shared by the foreign key and the principal key.

Exceptions

ArgumentNullException

A selector is null.

NotSupportedException

A selector does not select a property, or the navigation is a value type or string.

HasOne<TChild, TKey>(Expression<Func<T, TKey>>, Expression<Func<TChild, TKey>>)

Declares the dependent side of a many-to-one relationship for an entity whose navigation is not modelled as a property: the foreign key is selected on this entity and the principal key on the related type, and no navigation is attached.

public EntityMetadataBuilder<T> HasOne<TChild, TKey>(Expression<Func<T, TKey>> foreignKey, Expression<Func<TChild, TKey>> principalKey) where TChild : class

Parameters

foreignKey Expression<Func<T, TKey>>

Selects the foreign-key property on this entity, for example c => c.ParentId.

principalKey Expression<Func<TChild, TKey>>

Selects the principal-key property on TChild, for example p => p.Id.

Returns

EntityMetadataBuilder<T>

This builder, for chaining.

Type Parameters

TChild

The principal entity type.

TKey

The property type shared by the foreign key and the principal key.

Exceptions

ArgumentNullException

A selector is null.

NotSupportedException

A selector does not select a property.

HasQueryFilter(Func<EntityBuilder<T>, IDataContext, EntityBuilder<T>>)

Declares an anonymous global query filter in the builder-function form. The function receives a builder over the entity and the executing IDataContext, and must express the filter by calling Where; only that predicate is merged into every query in which the entity participates. The function is invoked once while the plan is built. Values that must stay parameterised (so the plan can be cached) have to be read from the IDataContext or supplied through SqlFunctions.Parameter<T>(idx); snapshotting a runtime value into a local before the Where call, or changing anything other than Where, is rejected. A repeated anonymous call on this builder adds another filter. The mapping is registered once per entity type: a later From<T>(...) configuration for the same type is ignored, so the first registration wins.

public EntityMetadataBuilder<T> HasQueryFilter(Func<EntityBuilder<T>, IDataContext, EntityBuilder<T>> filter)

Parameters

filter Func<EntityBuilder<T>, IDataContext, EntityBuilder<T>>

The filter function that appends the predicate with Where.

Returns

EntityMetadataBuilder<T>

This builder, for chaining.

HasQueryFilter(Expression<Func<T, IDataContext, bool>>)

Declares an anonymous global query filter that is applied to every query in which the entity participates (the primary source, joins and subqueries) unless the query calls IgnoreFilters. The predicate receives the executing IDataContext so it can read per-context state such as a tenant identifier. A repeated anonymous call on this builder adds another predicate; the declared anonymous filters are combined with and. The mapping is registered once per entity type: a later From<T>(...) configuration for the same type is ignored, so the first registration wins.

public EntityMetadataBuilder<T> HasQueryFilter(Expression<Func<T, IDataContext, bool>> filter)

Parameters

filter Expression<Func<T, IDataContext, bool>>

The filter predicate over the entity and the executing data context.

Returns

EntityMetadataBuilder<T>

This builder, for chaining.

HasQueryFilter(Expression<Func<T, bool>>)

Declares an anonymous global query filter that is applied to every query in which the entity participates (the primary source, joins and subqueries) unless the query calls IgnoreFilters. A repeated anonymous call on this builder adds another predicate; the declared anonymous filters are combined with and. The mapping is registered once per entity type: a later From<T>(...) configuration for the same type is ignored, so the first registration wins.

public EntityMetadataBuilder<T> HasQueryFilter(Expression<Func<T, bool>> filter)

Parameters

filter Expression<Func<T, bool>>

The filter predicate over the entity.

Returns

EntityMetadataBuilder<T>

This builder, for chaining.

HasQueryFilter(string, Func<EntityBuilder<T>, IDataContext, EntityBuilder<T>>?)

Declares a named global query filter in the builder-function form: the key occupies a slot so the filter can be targeted by the key-based IgnoreFilters overload. A repeated call with the same key replaces the earlier filter; passing a null filter removes the slot. The function receives the executing IDataContext and must express the filter by calling Where; only that predicate is merged. The mapping is registered once per entity type: a later From<T>(...) configuration for the same type is ignored, so the first registration wins.

public EntityMetadataBuilder<T> HasQueryFilter(string filterKey, Func<EntityBuilder<T>, IDataContext, EntityBuilder<T>>? filter)

Parameters

filterKey string

The filter key; null, empty or whitespace declares an anonymous filter.

filter Func<EntityBuilder<T>, IDataContext, EntityBuilder<T>>

The filter function that appends the predicate with Where, or null to remove the named slot.

Returns

EntityMetadataBuilder<T>

This builder, for chaining.

HasQueryFilter(string, Expression<Func<T, IDataContext, bool>>?)

Declares a named global query filter: the key occupies a slot so the filter can be targeted by the key-based IgnoreFilters overload. A repeated call with the same key replaces the earlier filter; passing a null filter removes the slot. The predicate receives the executing IDataContext. The mapping is registered once per entity type: a later From<T>(...) configuration for the same type is ignored, so the first registration wins.

public EntityMetadataBuilder<T> HasQueryFilter(string filterKey, Expression<Func<T, IDataContext, bool>>? filter)

Parameters

filterKey string

The filter key; null, empty or whitespace declares an anonymous filter.

filter Expression<Func<T, IDataContext, bool>>

The context-aware filter predicate, or null to remove the named slot.

Returns

EntityMetadataBuilder<T>

This builder, for chaining.

Property(Expression<Func<T, object>>)

Declares a fluent mapping for the property selected by propertySelector.

public EntityPropertyBuilder<T> Property(Expression<Func<T, object>> propertySelector)

Parameters

propertySelector Expression<Func<T, object>>

Selects the property to map; the expression must produce a PropertyInfo.

Returns

EntityPropertyBuilder<T>

A builder for the selected property's column mapping.

Table(string)

Overrides the table name for the entity instead of deriving it from the CLR type or attributes.

public EntityMetadataBuilder<T> Table(string tableName)

Parameters

tableName string

The table name to map the entity to.

Returns

EntityMetadataBuilder<T>

This builder, for chaining.