Table of Contents

Interface IConventionForeignKeyBuilder

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

Provides a simple API surface for configuring an IConventionForeignKey from conventions.

This interface is typically used by database providers (and other extensions). It is generally not used in application code.

public interface IConventionForeignKeyBuilder : IConventionAnnotatableBuilder
Inherited Members

Remarks

See Model building conventions for more information and examples.

Properties

Metadata

Gets the foreign key being configured.

IConventionForeignKey Metadata { get; }

Property Value

IConventionForeignKey

Methods

CanInvert(IReadOnlyList<IConventionProperty>?, bool)

Returns a value indicating whether the principal and dependent entity types can be switched from the current configuration source

bool CanInvert(IReadOnlyList<IConventionProperty>? newForeignKeyProperties, bool fromDataAnnotation = false)

Parameters

newForeignKeyProperties IReadOnlyList<IConventionProperty>

The properties to be used as the new foreign key or null to use any compatible properties.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool

true if the principal and dependent entity types can be switched.

CanSetEntityTypes(IConventionEntityType, IConventionEntityType, bool)

Returns a value indicating whether the principal and dependent types can be switched or the relationship could be moved to a base type of one of the participating entity types.

bool CanSetEntityTypes(IConventionEntityType principalEntityType, IConventionEntityType dependentEntityType, bool fromDataAnnotation = false)

Parameters

principalEntityType IConventionEntityType

The principal entity type to set.

dependentEntityType IConventionEntityType

The dependent entity type to set.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool

true if the principal and dependent entity types can be switched or the relationship could be moved to a base type of one of the participating entity types.

CanSetForeignKey(IReadOnlyList<IConventionProperty>?, bool)

Returns a value indicating whether the given properties can be set as the foreign key for this relationship from the current configuration source.

bool CanSetForeignKey(IReadOnlyList<IConventionProperty>? properties, bool fromDataAnnotation = false)

Parameters

properties IReadOnlyList<IConventionProperty>

The properties to use as the foreign key for this relationship.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool

true if the given properties can be set as the foreign key.

CanSetForeignKey(IReadOnlyList<string>?, bool)

Returns a value indicating whether the given properties can be set as the foreign key for this relationship from the current configuration source.

bool CanSetForeignKey(IReadOnlyList<string>? propertyNames, bool fromDataAnnotation = false)

Parameters

propertyNames IReadOnlyList<string>

The properties to use as the foreign key for this relationship.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool

true if the given properties can be set as the foreign key.

CanSetIsOwnership(bool?, bool)

Returns a value indicating whether this relationship can be configured as defining an ownership or not from the current configuration source.

bool CanSetIsOwnership(bool? ownership, bool fromDataAnnotation = false)

Parameters

ownership bool?

A value indicating whether this relationship defines an ownership. null to reset to default.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool

true if the relationship can be configured as defining an ownership.

CanSetIsRequired(bool?, bool)

Returns a value indicating whether the relationship requiredness can be configured from the current configuration source.

bool CanSetIsRequired(bool? required, bool fromDataAnnotation = false)

Parameters

required bool?

A value indicating whether this is a required relationship. null to reset to default.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool

true if the relationship requiredness can be configured.

CanSetIsRequiredDependent(bool?, bool)

Returns a value indicating whether the dependent end requiredness can be configured from the current configuration source.

bool CanSetIsRequiredDependent(bool? required, bool fromDataAnnotation = false)

Parameters

required bool?

A value indicating whether this is a required relationship. null to reset to default.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool

true if the relationship requiredness can be configured.

CanSetIsUnique(bool?, bool)

Returns a value indicating whether this relationship uniqueness can be configured from the current configuration source.

bool CanSetIsUnique(bool? unique, bool fromDataAnnotation = false)

Parameters

unique bool?

A value indicating whether the dependent entity is unique. null to reset to default.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool

true if the relationship uniqueness can be configured.

CanSetNavigation(MemberInfo?, bool, bool)

Returns a value indicating whether the given property can be used as a navigation for this relationship from the current configuration source.

bool CanSetNavigation(MemberInfo? property, bool pointsToPrincipal, bool fromDataAnnotation = false)

Parameters

property MemberInfo

The property to use.

pointsToPrincipal bool

A value indicating whether the navigation is on the dependent type pointing to the principal type.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool

true if the given property can be used as a navigation.

CanSetNavigation(string?, bool, bool)

Returns a value indicating whether the property with the given name can be used as a navigation for this relationship from the current configuration source.

bool CanSetNavigation(string? name, bool pointsToPrincipal, bool fromDataAnnotation = false)

Parameters

name string

The name of the property to use.

pointsToPrincipal bool

A value indicating whether the navigation is on the dependent type pointing to the principal type.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool

true if the given property can be used as a navigation.

CanSetNavigations(MemberInfo?, MemberInfo?, bool)

Returns a value indicating whether the given properties can be used as the navigation properties for this relationship from the current configuration source

bool CanSetNavigations(MemberInfo? navigationToPrincipal, MemberInfo? navigationToDependent, bool fromDataAnnotation = false)

Parameters

navigationToPrincipal MemberInfo

The property to use as the navigation to the principal entity type. Can be null.

navigationToDependent MemberInfo

The property to use as the navigation to the dependent entity type. Can be null.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool

true if the given properties can be used as navigations.

CanSetNavigations(string?, string?, bool)

Returns a value indicating whether the properties with the given names can be used as the navigation properties for this relationship from the current configuration source

bool CanSetNavigations(string? navigationToPrincipalName, string? navigationToDependentName, bool fromDataAnnotation = false)

Parameters

navigationToPrincipalName string

The name of the property to use as the navigation to the principal entity type. Can be null.

navigationToDependentName string

The name of the property to use as the navigation to the dependent entity type. Can be null.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool

true if the given properties can be used as navigations.

CanSetOnDelete(DeleteBehavior??, bool)

Returns a value indicating whether the operation on principal deletion can be configured from the current configuration source.

bool CanSetOnDelete(DeleteBehavior?? deleteBehavior, bool fromDataAnnotation = false)

Parameters

deleteBehavior DeleteBehavior?

The action to perform. null to reset to default.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool

true if the operation on principal deletion can be configured

CanSetPrincipalKey(IReadOnlyList<IConventionProperty>?, bool)

Returns a value indicating whether the given properties can be set as the target for this relationship from the current configuration source

bool CanSetPrincipalKey(IReadOnlyList<IConventionProperty>? properties, bool fromDataAnnotation = false)

Parameters

properties IReadOnlyList<IConventionProperty>

The properties for this relationship to target.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool

true if the given properties can be set as the target.

CanSetPrincipalKey(IReadOnlyList<string>?, bool)

Returns a value indicating whether the given properties can be set as the target for this relationship from the current configuration source

bool CanSetPrincipalKey(IReadOnlyList<string>? propertyNames, bool fromDataAnnotation = false)

Parameters

propertyNames IReadOnlyList<string>

The properties for this relationship to target.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool

true if the given properties can be set as the target.

HasAnnotation(string, object?, bool)

Sets the annotation stored under the given name. Overwrites the existing annotation if an annotation with the specified name already exists with same or lower ConfigurationSource.

IConventionForeignKeyBuilder? HasAnnotation(string name, object? value, bool fromDataAnnotation = false)

Parameters

name string

The name of the annotation to be set.

value object

The value to be stored in the annotation.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionForeignKeyBuilder

An IConventionForeignKeyBuilder to continue configuration if the annotation was set, null otherwise.

HasEntityTypes(IConventionEntityType, IConventionEntityType, bool)

Configures which entity types participate in this relationship. By calling this method the principal and dependent types can be switched or the relationship could be moved to a base type of one of the participating entity types.

IConventionForeignKeyBuilder? HasEntityTypes(IConventionEntityType principalEntityType, IConventionEntityType dependentEntityType, bool fromDataAnnotation = false)

Parameters

principalEntityType IConventionEntityType

The principal entity type to set.

dependentEntityType IConventionEntityType

The dependent entity type to set.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionForeignKeyBuilder

A builder instance if the entity types were configured as related, null otherwise.

HasForeignKey(IReadOnlyList<IConventionProperty>?, bool)

Configures the properties to use as the foreign key for this relationship.

IConventionForeignKeyBuilder? HasForeignKey(IReadOnlyList<IConventionProperty>? properties, bool fromDataAnnotation = false)

Parameters

properties IReadOnlyList<IConventionProperty>

The properties to use as the foreign key for this relationship.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionForeignKeyBuilder

The same builder instance if the properties were configured as the foreign key, null otherwise.

HasForeignKey(IReadOnlyList<string>?, bool)

Configures the properties to use as the foreign key for this relationship.

IConventionForeignKeyBuilder? HasForeignKey(IReadOnlyList<string>? propertyNames, bool fromDataAnnotation = false)

Parameters

propertyNames IReadOnlyList<string>

The properties to use as the foreign key for this relationship.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionForeignKeyBuilder

The same builder instance if the properties were configured as the foreign key, null otherwise.

HasNavigation(MemberInfo?, bool, bool)

Configures the given property as a navigation property used by this relationship.

IConventionForeignKeyBuilder? HasNavigation(MemberInfo? property, bool pointsToPrincipal, bool fromDataAnnotation = false)

Parameters

property MemberInfo

The property to use.

pointsToPrincipal bool

A value indicating whether the navigation is on the dependent type pointing to the principal type.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionForeignKeyBuilder

The same builder instance if the navigation property was configured, null otherwise.

HasNavigation(string?, bool, bool)

Configures the property with the given name as a navigation property used by this relationship.

IConventionForeignKeyBuilder? HasNavigation(string? name, bool pointsToPrincipal, bool fromDataAnnotation = false)

Parameters

name string

The name of the property to use.

pointsToPrincipal bool

A value indicating whether the navigation is on the dependent type pointing to the principal type.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionForeignKeyBuilder

The same builder instance if the navigation property was configured, null otherwise.

HasNavigations(MemberInfo?, MemberInfo?, bool)

Configures the given properties as the navigation properties used by this relationship.

IConventionForeignKeyBuilder? HasNavigations(MemberInfo? navigationToPrincipal, MemberInfo? navigationToDependent, bool fromDataAnnotation = false)

Parameters

navigationToPrincipal MemberInfo

The property to use as the navigation to the principal entity type. Can be null.

navigationToDependent MemberInfo

The property to use as the navigation to the dependent entity type. Can be null.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionForeignKeyBuilder

The same builder instance if the navigation properties were configured, null otherwise.

HasNavigations(string?, string?, bool)

Configures the properties with the given names as the navigation properties used by this relationship.

IConventionForeignKeyBuilder? HasNavigations(string? navigationToPrincipalName, string? navigationToDependentName, bool fromDataAnnotation = false)

Parameters

navigationToPrincipalName string

The name of the property to use as the navigation to the principal entity type. Can be null.

navigationToDependentName string

The name of the property to use as the navigation to the dependent entity type. Can be null.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionForeignKeyBuilder

The same builder instance if the navigation properties were configured, null otherwise.

HasNoAnnotation(string, bool)

Removes the annotation with the given name from this object.

IConventionForeignKeyBuilder? HasNoAnnotation(string name, bool fromDataAnnotation = false)

Parameters

name string

The name of the annotation to remove.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionForeignKeyBuilder

An IConventionForeignKeyBuilder to continue configuration if the annotation was set, null otherwise.

HasNonNullAnnotation(string, object?, bool)

Sets the annotation stored under the given name. Overwrites the existing annotation if an annotation with the specified name already exists with same or lower ConfigurationSource. Removes the annotation if null value is specified.

IConventionForeignKeyBuilder? HasNonNullAnnotation(string name, object? value, bool fromDataAnnotation = false)

Parameters

name string

The name of the annotation to be set.

value object

The value to be stored in the annotation. null to remove the annotations.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionForeignKeyBuilder

An IConventionForeignKeyBuilder to continue configuration if the annotation was set or removed, null otherwise.

HasPrincipalKey(IReadOnlyList<IConventionProperty>?, bool)

Configures the properties that this relationship targets.

IConventionForeignKeyBuilder? HasPrincipalKey(IReadOnlyList<IConventionProperty>? properties, bool fromDataAnnotation = false)

Parameters

properties IReadOnlyList<IConventionProperty>

The properties for this relationship to target.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionForeignKeyBuilder

The same builder instance if the properties were configured as the target for this relationship, null otherwise.

HasPrincipalKey(IReadOnlyList<string>?, bool)

Configures the properties that this relationship targets.

IConventionForeignKeyBuilder? HasPrincipalKey(IReadOnlyList<string>? propertyNames, bool fromDataAnnotation = false)

Parameters

propertyNames IReadOnlyList<string>

The properties for this relationship to target.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionForeignKeyBuilder

The same builder instance if the properties were configured as the target for this relationship, null otherwise.

IsOwnership(bool?, bool)

Configures whether this relationship defines an ownership (i.e. whether the dependent entity must always be accessed via the navigation from the principal entity).

IConventionForeignKeyBuilder? IsOwnership(bool? ownership, bool fromDataAnnotation = false)

Parameters

ownership bool?

A value indicating whether this relationship defines an ownership. null to reset to default.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionForeignKeyBuilder

The same builder instance if the ownership was configured, null otherwise.

IsRequired(bool?, bool)

Configures whether this is a required relationship (i.e. whether none of the foreign key properties can be assigned null).

IConventionForeignKeyBuilder? IsRequired(bool? required, bool fromDataAnnotation = false)

Parameters

required bool?

A value indicating whether this is a required relationship. null to reset to default.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionForeignKeyBuilder

The same builder instance if the requiredness was configured, null otherwise.

IsRequiredDependent(bool?, bool)

Configures whether the dependent end is required (i.e. whether the principal to dependent navigation can be assigned null).

IConventionForeignKeyBuilder? IsRequiredDependent(bool? required, bool fromDataAnnotation = false)

Parameters

required bool?

A value indicating whether the dependent end is required. null to reset to default.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionForeignKeyBuilder

The same builder instance if the dependent end requiredness was configured, null otherwise.

IsUnique(bool?, bool)

Configures whether the dependent entity is unique (i.e. whether the navigation to the dependent entity type is not a collection).

IConventionForeignKeyBuilder? IsUnique(bool? unique, bool fromDataAnnotation = false)

Parameters

unique bool?

A value indicating whether the dependent entity is unique. null to reset to default.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionForeignKeyBuilder

The same builder instance if the uniqueness was configured, null otherwise.

OnDelete(DeleteBehavior??, bool)

Configures the operation applied to dependent entities in the relationship when the principal is deleted or the relationship is severed.

IConventionForeignKeyBuilder? OnDelete(DeleteBehavior?? deleteBehavior, bool fromDataAnnotation = false)

Parameters

deleteBehavior DeleteBehavior?

The action to perform. null to reset to default.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionForeignKeyBuilder

The same builder instance if the delete operation was configured, null otherwise.