Table of Contents

Class ReferenceNavigationBuilder<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 reference that points to an instance of another entity type.

public class ReferenceNavigationBuilder<TEntity, TRelatedEntity> : ReferenceNavigationBuilder, 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
ReferenceNavigationBuilder<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.

See Modeling entity types and relationships for more information and examples.

Constructors

ReferenceNavigationBuilder(IMutableEntityType, IMutableEntityType, MemberInfo?, IMutableForeignKey)

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 ReferenceNavigationBuilder(IMutableEntityType declaringEntityType, IMutableEntityType relatedEntityType, MemberInfo? navigationMemberInfo, IMutableForeignKey foreignKey)

Parameters

declaringEntityType IMutableEntityType
relatedEntityType IMutableEntityType
navigationMemberInfo MemberInfo
foreignKey IMutableForeignKey

ReferenceNavigationBuilder(IMutableEntityType, IMutableEntityType, string?, IMutableForeignKey)

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 ReferenceNavigationBuilder(IMutableEntityType declaringEntityType, IMutableEntityType relatedEntityType, string? navigationName, IMutableForeignKey foreignKey)

Parameters

declaringEntityType IMutableEntityType
relatedEntityType IMutableEntityType
navigationName string
foreignKey IMutableForeignKey

Methods

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

Configures this as a one-to-many relationship.

public virtual ReferenceCollectionBuilder<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). If no property is specified, the relationship will be configured without a navigation property on the other end of the relationship.

Returns

ReferenceCollectionBuilder<TRelatedEntity, TEntity>

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.

WithMany(string?)

Configures this as a one-to-many relationship.

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

Parameters

navigationName string

The name of the collection navigation property on the other end of this relationship. If null or not specified, there is no navigation property on the other end of the relationship.

Returns

ReferenceCollectionBuilder<TRelatedEntity, TEntity>

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(Expression<Func<TRelatedEntity, TEntity?>>?)

Configures this as a one-to-one relationship.

public virtual ReferenceReferenceBuilder<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 (blog => blog.BlogInfo). If no property is specified, the relationship will be configured without a navigation property on the other end of the relationship.

Returns

ReferenceReferenceBuilder<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-one relationship.

public virtual ReferenceReferenceBuilder<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 or not specified, there is no navigation property on the other end of the relationship.

Returns

ReferenceReferenceBuilder<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.