Table of Contents

Class CollectionNavigationBuilder<TEntity, TRelatedEntity>

Namespace
Microsoft.EntityFrameworkCore.Metadata.Builders
Assembly
Microsoft.EntityFrameworkCore.dll

Provides a simple API for configuring a relationship where configuration began on an end of the relationship with a collection that contains instances of another entity type.

public class CollectionNavigationBuilder<TEntity, TRelatedEntity> : CollectionNavigationBuilder, IInfrastructure<IConventionForeignKeyBuilder?> where TEntity : class where TRelatedEntity : class

Type Parameters

TEntity

The entity type to be configured.

TRelatedEntity

The entity type that this relationship targets.

Inheritance
CollectionNavigationBuilder<TEntity, TRelatedEntity>
Implements
Inherited Members
Extension Methods

Remarks

Instances of this class are returned from methods when using the ModelBuilder API and it is not designed to be directly constructed in your application code.

Constructors

CollectionNavigationBuilder(IMutableEntityType, IMutableEntityType, MemberIdentity, IMutableForeignKey?, IMutableSkipNavigation?)

This is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release. You should only use it directly in your code with extreme caution and knowing that doing so can result in application failures when updating to a new Entity Framework Core release.

[EntityFrameworkInternal]
public CollectionNavigationBuilder(IMutableEntityType declaringEntityType, IMutableEntityType relatedEntityType, MemberIdentity navigation, IMutableForeignKey? foreignKey, IMutableSkipNavigation? skipNavigation)

Parameters

declaringEntityType IMutableEntityType
relatedEntityType IMutableEntityType
navigation MemberIdentity
foreignKey IMutableForeignKey
skipNavigation IMutableSkipNavigation

Methods

WithMany(Expression<Func<TRelatedEntity, IEnumerable<TEntity>?>>)

Configures this as a many-to-many relationship.

public virtual CollectionCollectionBuilder<TRelatedEntity, TEntity> WithMany(Expression<Func<TRelatedEntity, IEnumerable<TEntity>?>> navigationExpression)

Parameters

navigationExpression Expression<Func<TRelatedEntity, IEnumerable<TEntity>>>

A lambda expression representing the collection navigation property on the other end of this relationship (blog => blog.Posts).

Returns

CollectionCollectionBuilder<TRelatedEntity, TEntity>

An object to further configure the relationship.

WithMany(string?)

Configures this as a many-to-many relationship.

public virtual CollectionCollectionBuilder<TRelatedEntity, TEntity> WithMany(string? navigationName = null)

Parameters

navigationName string

The name of the collection navigation property on the other end of this relationship. Can be null to create a unidirectional relationship.

Returns

CollectionCollectionBuilder<TRelatedEntity, TEntity>

An object to further configure the relationship.

WithOne(Expression<Func<TRelatedEntity, TEntity?>>?)

Configures this as a one-to-many relationship.

public virtual ReferenceCollectionBuilder<TEntity, TRelatedEntity> WithOne(Expression<Func<TRelatedEntity, TEntity?>>? navigationExpression)

Parameters

navigationExpression Expression<Func<TRelatedEntity, TEntity>>

A lambda expression representing the reference navigation property on the other end of this relationship (post => post.Blog). If no property is specified, the relationship will be configured without a navigation property on the other end of the relationship.

Returns

ReferenceCollectionBuilder<TEntity, TRelatedEntity>

An object to further configure the relationship.

Remarks

Note that calling this method with no parameters will explicitly configure this side of the relationship to use no navigation property, even if such a property exists on the entity type. If the navigation property is to be used, then it must be specified.

WithOne(string?)

Configures this as a one-to-many relationship.

public virtual ReferenceCollectionBuilder<TEntity, TRelatedEntity> WithOne(string? navigationName = null)

Parameters

navigationName string

The name of the reference navigation property on the other end of this relationship. If null, there is no navigation property on the other end of the relationship.

Returns

ReferenceCollectionBuilder<TEntity, TRelatedEntity>

An object to further configure the relationship.