Table of Contents

Class NavigationBuilder

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

Provides a simple API for configuring a IMutableNavigation or IMutableSkipNavigation.

public class NavigationBuilder : IInfrastructure<IConventionSkipNavigationBuilder?>, IInfrastructure<IConventionNavigationBuilder?>
Inheritance
NavigationBuilder
Implements
Derived
Inherited Members

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

NavigationBuilder(IMutableNavigationBase)

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 NavigationBuilder(IMutableNavigationBase navigationOrSkipNavigation)

Parameters

navigationOrSkipNavigation IMutableNavigationBase

Properties

Metadata

The navigation being configured.

public virtual IMutableNavigationBase Metadata { get; }

Property Value

IMutableNavigationBase

Methods

AutoInclude(bool)

Configures whether this navigation should be automatically included in a query.

public virtual NavigationBuilder AutoInclude(bool autoInclude = true)

Parameters

autoInclude bool

A value indicating if the navigation should be automatically included.

Returns

NavigationBuilder

The same builder instance so that multiple configuration calls can be chained.

EnableLazyLoading(bool)

Configures whether this navigation should be enabled for lazy-loading. Note that a property can only be lazy-loaded if a lazy-loading mechanism such as lazy-loading proxies or Microsoft.EntityFrameworkCore.Infrastructure.ILazyLoader injection has been configured.

public virtual NavigationBuilder EnableLazyLoading(bool lazyLoadingEnabled = true)

Parameters

lazyLoadingEnabled bool

A value indicating if the navigation should be enabled for lazy-loading.

Returns

NavigationBuilder

The same builder instance so that multiple configuration calls can be chained.

Remarks

See Lazy loading for more information and examples.

HasAnnotation(string, object?)

Adds or updates an annotation on the navigation property. If an annotation with the key specified in annotation already exists its value will be updated.

public virtual NavigationBuilder HasAnnotation(string annotation, object? value)

Parameters

annotation string

The key of the annotation to be added or updated.

value object

The value to be stored in the annotation.

Returns

NavigationBuilder

The same builder instance so that multiple configuration calls can be chained.

HasField(string?)

Sets a backing field to use for this navigation property.

public virtual NavigationBuilder HasField(string? fieldName)

Parameters

fieldName string

The name of the field to use for this navigation property.

Returns

NavigationBuilder

The same builder instance so that multiple configuration calls can be chained.

IsRequired(bool)

Configures whether this navigation is required.

public virtual NavigationBuilder IsRequired(bool required = true)

Parameters

required bool

A value indicating whether the navigation should be required.

Returns

NavigationBuilder

The same builder instance so that multiple configuration calls can be chained.

UsePropertyAccessMode(PropertyAccessMode)

Sets the PropertyAccessMode to use for this property.

public virtual NavigationBuilder UsePropertyAccessMode(PropertyAccessMode propertyAccessMode)

Parameters

propertyAccessMode PropertyAccessMode

The PropertyAccessMode to use for this property.

Returns

NavigationBuilder

The same builder instance so that multiple configuration calls can be chained.

Remarks

By default, the backing field, if one is found by convention or has been specified, is used when new objects are constructed, typically when entities are queried from the database. Properties are used for all other accesses. Calling this method will change that behavior for this property as described in the PropertyAccessMode enum.

Calling this method overrides for this property any access mode that was set on the entity type or model.