IConventionEntityType.AddForeignKey Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
AddForeignKey(IConventionProperty, IConventionKey, IConventionEntityType, Boolean) |
Adds a new relationship to this entity type. |
AddForeignKey(IReadOnlyList<IConventionProperty>, IConventionKey, IConventionEntityType, Boolean, Boolean) |
Adds a new relationship to this entity type. |
AddForeignKey(IConventionProperty, IConventionKey, IConventionEntityType, Boolean)
Adds a new relationship to this entity type.
public virtual Microsoft.EntityFrameworkCore.Metadata.IConventionForeignKey? AddForeignKey (Microsoft.EntityFrameworkCore.Metadata.IConventionProperty property, Microsoft.EntityFrameworkCore.Metadata.IConventionKey principalKey, Microsoft.EntityFrameworkCore.Metadata.IConventionEntityType principalEntityType, bool fromDataAnnotation = false);
abstract member AddForeignKey : Microsoft.EntityFrameworkCore.Metadata.IConventionProperty * Microsoft.EntityFrameworkCore.Metadata.IConventionKey * Microsoft.EntityFrameworkCore.Metadata.IConventionEntityType * bool -> Microsoft.EntityFrameworkCore.Metadata.IConventionForeignKey
override this.AddForeignKey : Microsoft.EntityFrameworkCore.Metadata.IConventionProperty * Microsoft.EntityFrameworkCore.Metadata.IConventionKey * Microsoft.EntityFrameworkCore.Metadata.IConventionEntityType * bool -> Microsoft.EntityFrameworkCore.Metadata.IConventionForeignKey
Public Overridable Function AddForeignKey (property As IConventionProperty, principalKey As IConventionKey, principalEntityType As IConventionEntityType, Optional fromDataAnnotation As Boolean = false) As IConventionForeignKey
Parameters
- property
- IConventionProperty
The property that the foreign key is defined on.
- principalKey
- IConventionKey
The primary or alternate key that is referenced.
- principalEntityType
- IConventionEntityType
The entity type that the relationship targets. This may be different from the type that principalKey
is defined on when the relationship targets a derived type in an inheritance hierarchy (since the key is defined on the
base type of the hierarchy).
- fromDataAnnotation
- Boolean
Indicates whether the configuration was specified using a data annotation.
Returns
The newly created foreign key.
Applies to
AddForeignKey(IReadOnlyList<IConventionProperty>, IConventionKey, IConventionEntityType, Boolean, Boolean)
Adds a new relationship to this entity type.
public Microsoft.EntityFrameworkCore.Metadata.IConventionForeignKey AddForeignKey (System.Collections.Generic.IReadOnlyList<Microsoft.EntityFrameworkCore.Metadata.IConventionProperty> properties, Microsoft.EntityFrameworkCore.Metadata.IConventionKey principalKey, Microsoft.EntityFrameworkCore.Metadata.IConventionEntityType principalEntityType, bool setComponentConfigurationSource = true, bool fromDataAnnotation = false);
public Microsoft.EntityFrameworkCore.Metadata.IConventionForeignKey? AddForeignKey (System.Collections.Generic.IReadOnlyList<Microsoft.EntityFrameworkCore.Metadata.IConventionProperty> properties, Microsoft.EntityFrameworkCore.Metadata.IConventionKey principalKey, Microsoft.EntityFrameworkCore.Metadata.IConventionEntityType principalEntityType, bool setComponentConfigurationSource = true, bool fromDataAnnotation = false);
abstract member AddForeignKey : System.Collections.Generic.IReadOnlyList<Microsoft.EntityFrameworkCore.Metadata.IConventionProperty> * Microsoft.EntityFrameworkCore.Metadata.IConventionKey * Microsoft.EntityFrameworkCore.Metadata.IConventionEntityType * bool * bool -> Microsoft.EntityFrameworkCore.Metadata.IConventionForeignKey
Public Function AddForeignKey (properties As IReadOnlyList(Of IConventionProperty), principalKey As IConventionKey, principalEntityType As IConventionEntityType, Optional setComponentConfigurationSource As Boolean = true, Optional fromDataAnnotation As Boolean = false) As IConventionForeignKey
Parameters
- properties
- IReadOnlyList<IConventionProperty>
The properties that the foreign key is defined on.
- principalKey
- IConventionKey
The primary or alternate key that is referenced.
- principalEntityType
- IConventionEntityType
The entity type that the relationship targets. This may be different from the type that principalKey
is defined on when the relationship targets a derived type in an inheritance hierarchy (since the key is defined on the
base type of the hierarchy).
- setComponentConfigurationSource
- Boolean
Indicates whether the configuration source should be set for the properties, principal key and principal end.
- fromDataAnnotation
- Boolean
Indicates whether the configuration was specified using a data annotation.
Returns
The newly created foreign key.
Applies to
Entity Framework
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for