Class ForeignKeyPropertyDiscoveryConvention
- Namespace
- Microsoft.EntityFrameworkCore.Metadata.Conventions
- Assembly
- Microsoft.EntityFrameworkCore.dll
A convention that finds foreign key properties for relationships based on their names, ignoring case:
- [navigation property name][principal key property name]
- [navigation property name]Id
- [principal entity name][principal key property name]
- [principal entity name]Id
public class ForeignKeyPropertyDiscoveryConvention : IEntityTypeMemberIgnoredConvention, IEntityTypePrimaryKeyChangedConvention, IForeignKeyAddedConvention, IForeignKeyPropertiesChangedConvention, IForeignKeyPrincipalEndChangedConvention, IForeignKeyUniquenessChangedConvention, IForeignKeyRequirednessChangedConvention, IKeyAddedConvention, IKeyRemovedConvention, INavigationAddedConvention, ISkipNavigationForeignKeyChangedConvention, ISkipNavigationInverseChangedConvention, IPropertyAddedConvention, IPropertyNullabilityChangedConvention, IPropertyFieldChangedConvention, IModelFinalizingConvention, IConvention
- Inheritance
-
ForeignKeyPropertyDiscoveryConvention
- Implements
- Inherited Members
Remarks
If no matching properties were found, the relationship doesn't represent an ownership, the dependent side is not ambiguous and not derived then if the relationship is one-to-one, the primary key properties are used, otherwise the convention tries to match properties with the exact name as principal key properties if they are a proper subset of the dependent PK.
If a match was found, but the property types are not compatible with the principal key types no further matches are searched for.
If the relationship uses shadow properties created by convention they are recreated to remove suffixes used to make the names unique.
See Model building conventions for more information and examples.
Constructors
ForeignKeyPropertyDiscoveryConvention(ProviderConventionSetBuilderDependencies)
Creates a new instance of ForeignKeyPropertyDiscoveryConvention.
public ForeignKeyPropertyDiscoveryConvention(ProviderConventionSetBuilderDependencies dependencies)
Parameters
dependencies
ProviderConventionSetBuilderDependenciesParameter object containing dependencies for this convention.
Properties
Dependencies
Dependencies for this service.
protected virtual ProviderConventionSetBuilderDependencies Dependencies { get; }
Property Value
Methods
GetPropertyBaseName(IReadOnlyForeignKey)
Gets the string that should be used as part of the shadow properties created for the given foreign key.
public static string GetPropertyBaseName(IReadOnlyForeignKey foreignKey)
Parameters
foreignKey
IReadOnlyForeignKeyThe foreign key.
Returns
- string
The string that should be used as part of the shadow properties created for the given foreign key.
ProcessEntityTypeMemberIgnored(IConventionEntityTypeBuilder, string, IConventionContext<string>)
Called after an entity type member is ignored.
public virtual void ProcessEntityTypeMemberIgnored(IConventionEntityTypeBuilder entityTypeBuilder, string name, IConventionContext<string> context)
Parameters
entityTypeBuilder
IConventionEntityTypeBuilderThe builder for the entity type.
name
stringThe name of the ignored member.
context
IConventionContext<string>Additional information associated with convention execution.
ProcessEntityTypePrimaryKeyChanged(IConventionEntityTypeBuilder, IConventionKey?, IConventionKey?, IConventionContext<IConventionKey>)
Called after the primary key for an entity type is changed.
public virtual void ProcessEntityTypePrimaryKeyChanged(IConventionEntityTypeBuilder entityTypeBuilder, IConventionKey? newPrimaryKey, IConventionKey? previousPrimaryKey, IConventionContext<IConventionKey> context)
Parameters
entityTypeBuilder
IConventionEntityTypeBuilderThe builder for the entity type.
newPrimaryKey
IConventionKeyThe new primary key.
previousPrimaryKey
IConventionKeyThe old primary key.
context
IConventionContext<IConventionKey>Additional information associated with convention execution.
ProcessForeignKeyAdded(IConventionForeignKeyBuilder, IConventionContext<IConventionForeignKeyBuilder>)
Called after a foreign key is added to the entity type.
public virtual void ProcessForeignKeyAdded(IConventionForeignKeyBuilder relationshipBuilder, IConventionContext<IConventionForeignKeyBuilder> context)
Parameters
relationshipBuilder
IConventionForeignKeyBuilderThe builder for the foreign key.
context
IConventionContext<IConventionForeignKeyBuilder>Additional information associated with convention execution.
ProcessForeignKeyPrincipalEndChanged(IConventionForeignKeyBuilder, IConventionContext<IConventionForeignKeyBuilder>)
Called after the principal end of a foreign key is changed.
public virtual void ProcessForeignKeyPrincipalEndChanged(IConventionForeignKeyBuilder relationshipBuilder, IConventionContext<IConventionForeignKeyBuilder> context)
Parameters
relationshipBuilder
IConventionForeignKeyBuilderThe builder for the foreign key.
context
IConventionContext<IConventionForeignKeyBuilder>Additional information associated with convention execution.
ProcessForeignKeyPropertiesChanged(IConventionForeignKeyBuilder, IReadOnlyList<IConventionProperty>, IConventionKey, IConventionContext<IReadOnlyList<IConventionProperty>>)
Called after the foreign key properties or principal key are changed.
public virtual void ProcessForeignKeyPropertiesChanged(IConventionForeignKeyBuilder relationshipBuilder, IReadOnlyList<IConventionProperty> oldDependentProperties, IConventionKey oldPrincipalKey, IConventionContext<IReadOnlyList<IConventionProperty>> context)
Parameters
relationshipBuilder
IConventionForeignKeyBuilderThe builder for the foreign key.
oldDependentProperties
IReadOnlyList<IConventionProperty>The old foreign key properties.
oldPrincipalKey
IConventionKeyThe old principal key.
context
IConventionContext<IReadOnlyList<IConventionProperty>>Additional information associated with convention execution.
ProcessForeignKeyRequirednessChanged(IConventionForeignKeyBuilder, IConventionContext<bool?>)
Called after the requiredness for a foreign key is changed.
public virtual void ProcessForeignKeyRequirednessChanged(IConventionForeignKeyBuilder relationshipBuilder, IConventionContext<bool?> context)
Parameters
relationshipBuilder
IConventionForeignKeyBuilderThe builder for the foreign key.
context
IConventionContext<bool?>Additional information associated with convention execution.
ProcessForeignKeyUniquenessChanged(IConventionForeignKeyBuilder, IConventionContext<bool?>)
Called after the uniqueness for a foreign key is changed.
public virtual void ProcessForeignKeyUniquenessChanged(IConventionForeignKeyBuilder relationshipBuilder, IConventionContext<bool?> context)
Parameters
relationshipBuilder
IConventionForeignKeyBuilderThe builder for the foreign key.
context
IConventionContext<bool?>Additional information associated with convention execution.
ProcessKeyAdded(IConventionKeyBuilder, IConventionContext<IConventionKeyBuilder>)
Called after a key is added to the entity type.
public virtual void ProcessKeyAdded(IConventionKeyBuilder keyBuilder, IConventionContext<IConventionKeyBuilder> context)
Parameters
keyBuilder
IConventionKeyBuilderThe builder for the key.
context
IConventionContext<IConventionKeyBuilder>Additional information associated with convention execution.
ProcessKeyRemoved(IConventionEntityTypeBuilder, IConventionKey, IConventionContext<IConventionKey>)
public virtual void ProcessKeyRemoved(IConventionEntityTypeBuilder entityTypeBuilder, IConventionKey key, IConventionContext<IConventionKey> context)
Parameters
entityTypeBuilder
IConventionEntityTypeBuilderkey
IConventionKeycontext
IConventionContext<IConventionKey>
ProcessModelFinalizing(IConventionModelBuilder, IConventionContext<IConventionModelBuilder>)
public virtual void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, IConventionContext<IConventionModelBuilder> context)
Parameters
modelBuilder
IConventionModelBuildercontext
IConventionContext<IConventionModelBuilder>
ProcessNavigationAdded(IConventionNavigationBuilder, IConventionContext<IConventionNavigationBuilder>)
public virtual void ProcessNavigationAdded(IConventionNavigationBuilder navigationBuilder, IConventionContext<IConventionNavigationBuilder> context)
Parameters
navigationBuilder
IConventionNavigationBuildercontext
IConventionContext<IConventionNavigationBuilder>
ProcessPropertyAdded(IConventionPropertyBuilder, IConventionContext<IConventionPropertyBuilder>)
Called after a property is added to the entity type.
public virtual void ProcessPropertyAdded(IConventionPropertyBuilder propertyBuilder, IConventionContext<IConventionPropertyBuilder> context)
Parameters
propertyBuilder
IConventionPropertyBuilderThe builder for the property.
context
IConventionContext<IConventionPropertyBuilder>Additional information associated with convention execution.
ProcessPropertyFieldChanged(IConventionPropertyBuilder, FieldInfo?, FieldInfo?, IConventionContext<FieldInfo>)
Called after the backing field for a property is changed.
public virtual void ProcessPropertyFieldChanged(IConventionPropertyBuilder propertyBuilder, FieldInfo? newFieldInfo, FieldInfo? oldFieldInfo, IConventionContext<FieldInfo> context)
Parameters
propertyBuilder
IConventionPropertyBuilderThe builder for the property.
newFieldInfo
FieldInfoThe new field.
oldFieldInfo
FieldInfoThe old field.
context
IConventionContext<FieldInfo>Additional information associated with convention execution.
ProcessPropertyNullabilityChanged(IConventionPropertyBuilder, IConventionContext<bool?>)
Called after the nullability for a property is changed.
public virtual void ProcessPropertyNullabilityChanged(IConventionPropertyBuilder propertyBuilder, IConventionContext<bool?> context)
Parameters
propertyBuilder
IConventionPropertyBuilderThe builder for the property.
context
IConventionContext<bool?>Additional information associated with convention execution.
ProcessSkipNavigationForeignKeyChanged(IConventionSkipNavigationBuilder, IConventionForeignKey?, IConventionForeignKey?, IConventionContext<IConventionForeignKey>)
public virtual void ProcessSkipNavigationForeignKeyChanged(IConventionSkipNavigationBuilder skipNavigationBuilder, IConventionForeignKey? foreignKey, IConventionForeignKey? oldForeignKey, IConventionContext<IConventionForeignKey> context)
Parameters
skipNavigationBuilder
IConventionSkipNavigationBuilderforeignKey
IConventionForeignKeyoldForeignKey
IConventionForeignKeycontext
IConventionContext<IConventionForeignKey>
ProcessSkipNavigationInverseChanged(IConventionSkipNavigationBuilder, IConventionSkipNavigation?, IConventionSkipNavigation?, IConventionContext<IConventionSkipNavigation>)
public virtual void ProcessSkipNavigationInverseChanged(IConventionSkipNavigationBuilder skipNavigationBuilder, IConventionSkipNavigation? inverse, IConventionSkipNavigation? oldInverse, IConventionContext<IConventionSkipNavigation> context)
Parameters
skipNavigationBuilder
IConventionSkipNavigationBuilderinverse
IConventionSkipNavigationoldInverse
IConventionSkipNavigationcontext
IConventionContext<IConventionSkipNavigation>