/// <summary> /// Sets the key constraint name for this key. /// </summary> /// <param name="key"> The key. </param> /// <param name="name"> The value to set. </param> /// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param> /// <returns> The configured name. </returns> public static string SetName([NotNull] this IConventionKey key, [CanBeNull] string name, bool fromDataAnnotation = false) { key.SetOrRemoveAnnotation( RelationalAnnotationNames.Name, Check.NullButNotEmpty(name, nameof(name)), fromDataAnnotation); return(name); }
public OnForeignKeyPropertiesChangedNode( IConventionForeignKeyBuilder relationshipBuilder, IReadOnlyList <IConventionProperty> oldDependentProperties, IConventionKey oldPrincipalKey) { RelationshipBuilder = relationshipBuilder; OldDependentProperties = oldDependentProperties; OldPrincipalKey = oldPrincipalKey; }
public virtual void ProcessKeyRemoved( IConventionEntityTypeBuilder entityTypeBuilder, IConventionKey key, IConventionContext <IConventionKey> context) { if (entityTypeBuilder.Metadata.FindPrimaryKey() == null) { TryConfigurePrimaryKey(entityTypeBuilder); } }
/// <summary> /// 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. /// </summary> public virtual void ProcessKeyRemoved( IConventionEntityTypeBuilder entityTypeBuilder, IConventionKey key, IConventionContext <IConventionKey> context) { foreach (var otherForeignKey in key.DeclaringEntityType.GetDerivedTypesInclusive() .SelectMany(t => t.GetDeclaredForeignKeys()) .Where(fk => AreIndexedBy(fk.Properties, fk.IsUnique, key.Properties, coveringIndexUnique: true))) { CreateIndex(otherForeignKey.Properties, otherForeignKey.IsUnique, otherForeignKey.DeclaringEntityType.Builder); } }
/// <summary> /// Adds a new relationship to this entity. /// </summary> /// <param name="entityType"> The entity type to add the foreign key to. </param> /// <param name="property"> The property that the foreign key is defined on. </param> /// <param name="principalKey"> The primary or alternate key that is referenced. </param> /// <param name="principalEntityType"> /// The entity type that the relationship targets. This may be different from the type that <paramref name="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). /// </param> /// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param> /// <returns> The newly created foreign key. </returns> public static IConventionForeignKey AddForeignKey( [NotNull] this IConventionEntityType entityType, [NotNull] IConventionProperty property, [NotNull] IConventionKey principalKey, [NotNull] IConventionEntityType principalEntityType, bool fromDataAnnotation = false) { Check.NotNull(entityType, nameof(entityType)); return(entityType.AddForeignKey(new[] { property }, principalKey, principalEntityType, fromDataAnnotation)); }
/// <inheritdoc /> public virtual void ProcessKeyRemoved( IConventionEntityTypeBuilder entityTypeBuilder, IConventionKey key, IConventionContext <IConventionKey> context) { if (entityTypeBuilder.Metadata.IsKeyless) { ProcessIdProperty(entityTypeBuilder); ProcessJObjectProperty(entityTypeBuilder); } }
/// <inheritdoc /> public virtual void ProcessEntityTypePrimaryKeyChanged( IConventionEntityTypeBuilder entityTypeBuilder, IConventionKey newPrimaryKey, IConventionKey previousPrimaryKey, IConventionContext <IConventionKey> context) { if ((newPrimaryKey != null && newPrimaryKey.Properties.Any(p => p.GetJsonPropertyName() == IdPropertyJsonName)) || (previousPrimaryKey != null && previousPrimaryKey.Properties.Any(p => p.GetJsonPropertyName() == IdPropertyJsonName))) { ProcessIdProperty(entityTypeBuilder); } }
/// <summary> /// Called after the foreign key properties or principal key are changed. /// </summary> /// <param name="relationshipBuilder"> The builder for the foreign key. </param> /// <param name="oldDependentProperties"> The old foreign key properties. </param> /// <param name="oldPrincipalKey"> The old principal key. </param> /// <param name="context"> Additional information associated with convention execution. </param> public virtual void ProcessForeignKeyPropertiesChanged( IConventionRelationshipBuilder relationshipBuilder, IReadOnlyList <IConventionProperty> oldDependentProperties, IConventionKey oldPrincipalKey, IConventionContext <IConventionRelationshipBuilder> context) { if (relationshipBuilder.Metadata.Builder == null || relationshipBuilder.Metadata.Properties == oldDependentProperties) { return; } ProcessForeignKeyAdded(relationshipBuilder, context); }
public virtual void ProcessForeignKeyPropertiesChanged( IConventionForeignKeyBuilder relationshipBuilder, IReadOnlyList <IConventionProperty> oldDependentProperties, IConventionKey oldPrincipalKey, IConventionContext <IReadOnlyList <IConventionProperty> > context) { var foreignKey = relationshipBuilder.Metadata; if (foreignKey.IsOwnership && !foreignKey.Properties.SequenceEqual(oldDependentProperties) && relationshipBuilder.Metadata.IsInModel) { TryConfigurePrimaryKey(foreignKey.DeclaringEntityType.Builder); } }
/// <summary> /// 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. /// </summary> public virtual void ProcessKeyRemoved( IConventionEntityTypeBuilder entityTypeBuilder, IConventionKey key, IConventionContext <IConventionKey> context) { var foreignKeys = key.DeclaringEntityType.GetDerivedTypesInclusive() .SelectMany(t => t.GetDeclaredForeignKeys()).ToList(); foreach (var foreignKey in foreignKeys) { if ((!foreignKey.IsUnique || foreignKey.DeclaringEntityType.BaseType != null)) { DiscoverProperties(foreignKey.Builder, context); } } }
public virtual void ProcessForeignKeyPropertiesChanged( IConventionForeignKeyBuilder relationshipBuilder, IReadOnlyList <IConventionProperty> oldDependentProperties, IConventionKey oldPrincipalKey, IConventionContext <IReadOnlyList <IConventionProperty> > context) { if (!relationshipBuilder.Metadata.IsInModel || relationshipBuilder.Metadata.Properties == oldDependentProperties) { return; } ProcessForeignKey(relationshipBuilder, context); context.StopProcessingIfChanged(relationshipBuilder.Metadata.Properties); }
/// <summary> /// Called after the foreign key properties or principal key are changed. /// </summary> /// <param name="relationshipBuilder"> The builder for the foreign key. </param> /// <param name="oldDependentProperties"> The old foreign key properties. </param> /// <param name="oldPrincipalKey"> The old principal key. </param> /// <param name="context"> Additional information associated with convention execution. </param> public virtual void ProcessForeignKeyPropertiesChanged( IConventionForeignKeyBuilder relationshipBuilder, IReadOnlyList <IConventionProperty> oldDependentProperties, IConventionKey oldPrincipalKey, IConventionContext <IReadOnlyList <IConventionProperty> > context) { var foreignKey = relationshipBuilder.Metadata; if (!foreignKey.Properties.SequenceEqual(oldDependentProperties)) { OnForeignKeyRemoved(foreignKey.DeclaringEntityType, oldDependentProperties); if (relationshipBuilder.Metadata.Builder != null) { CreateIndex(foreignKey.Properties, foreignKey.IsUnique, foreignKey.DeclaringEntityType.Builder); } } }
/// <summary> /// Called after the foreign key properties or principal key are changed. /// </summary> /// <param name="relationshipBuilder"> The builder for the foreign key. </param> /// <param name="oldDependentProperties"> The old foreign key properties. </param> /// <param name="oldPrincipalKey"> The old principal key. </param> /// <param name="context"> Additional information associated with convention execution. </param> public virtual void ProcessForeignKeyPropertiesChanged( IConventionRelationshipBuilder relationshipBuilder, IReadOnlyList <IConventionProperty> oldDependentProperties, IConventionKey oldPrincipalKey, IConventionContext <IConventionRelationshipBuilder> context) { var foreignKey = relationshipBuilder.Metadata; if (!foreignKey.Properties.SequenceEqual(oldDependentProperties)) { OnForeignKeyRemoved(oldDependentProperties); if (relationshipBuilder.Metadata.Builder != null) { foreach (var property in foreignKey.Properties) { property.Builder.ValueGenerated(ValueGenerated.Never); } } } }
public override IReadOnlyList <IConventionProperty>?OnForeignKeyPropertiesChanged( IConventionForeignKeyBuilder relationshipBuilder, IReadOnlyList <IConventionProperty> oldDependentProperties, IConventionKey oldPrincipalKey) { using (_dispatcher.DelayConventions()) { _propertyListConventionContext.ResetState(relationshipBuilder.Metadata.Properties); foreach (var foreignKeyConvention in _conventionSet.ForeignKeyPropertiesChangedConventions) { // Some conventions rely on this running even if the relationship has been removed // This will be fixed by reference counting, see #15898 //if (relationshipBuilder.Metadata.Builder == null) //{ // return null; //} foreignKeyConvention.ProcessForeignKeyPropertiesChanged( relationshipBuilder, oldDependentProperties, oldPrincipalKey, _propertyListConventionContext); if (_propertyListConventionContext.ShouldStopProcessing()) { if (_propertyListConventionContext.Result != null) { // Preserve the old configuration to let the conventions finish processing them _dispatcher.OnForeignKeyPropertiesChanged(relationshipBuilder, oldDependentProperties, oldPrincipalKey); } return(_propertyListConventionContext.Result); } } } if (!relationshipBuilder.Metadata.IsInModel) { return(null); } return(relationshipBuilder.Metadata.Properties); }
/// <summary> /// Called after the primary key for an entity type is changed. /// </summary> /// <param name="entityTypeBuilder"> The builder for the entity type. </param> /// <param name="newPrimaryKey"> The new primary key. </param> /// <param name="previousPrimaryKey"> The old primary key. </param> /// <param name="context"> Additional information associated with convention execution. </param> public virtual void ProcessEntityTypePrimaryKeyChanged( IConventionEntityTypeBuilder entityTypeBuilder, IConventionKey newPrimaryKey, IConventionKey previousPrimaryKey, IConventionContext <IConventionKey> context) { if (previousPrimaryKey != null) { foreach (var property in previousPrimaryKey.Properties) { property.Builder?.ValueGenerated(ValueGenerated.Never); } } if (newPrimaryKey?.Builder != null) { foreach (var property in newPrimaryKey.Properties) { property.Builder.ValueGenerated(GetValueGenerated(property)); } } }
/// <summary> /// Called after the foreign key properties or principal key are changed. /// </summary> /// <param name="relationshipBuilder">The builder for the foreign key.</param> /// <param name="oldDependentProperties">The old foreign key properties.</param> /// <param name="oldPrincipalKey">The old principal key.</param> /// <param name="context">Additional information associated with convention execution.</param> public virtual void ProcessForeignKeyPropertiesChanged( IConventionForeignKeyBuilder relationshipBuilder, IReadOnlyList <IConventionProperty> oldDependentProperties, IConventionKey oldPrincipalKey, IConventionContext <IReadOnlyList <IConventionProperty> > context) { var foreignKey = relationshipBuilder.Metadata; if (!foreignKey.Properties.SequenceEqual(oldDependentProperties)) { OnForeignKeyRemoved(oldDependentProperties); if (relationshipBuilder.Metadata.IsInModel && !foreignKey.IsBaseLinking()) { foreach (var property in foreignKey.Properties) { property.Builder.ValueGenerated(GetValueGenerated(property)); } } } }
public override IConventionKey OnEntityTypePrimaryKeyChanged( IConventionEntityTypeBuilder entityTypeBuilder, IConventionKey newPrimaryKey, IConventionKey previousPrimaryKey) { if (entityTypeBuilder.Metadata.Builder == null) { return(null); } using (_dispatcher.DelayConventions()) { _keyConventionContext.ResetState(newPrimaryKey); foreach (var keyConvention in _conventionSet.EntityTypePrimaryKeyChangedConventions) { // Some conventions rely on this running even if the new key has been removed // This will be fixed by reference counting, see #15898 //if (newPrimaryKey != null && newPrimaryKey.Builder == null) //{ //return null; //} keyConvention.ProcessEntityTypePrimaryKeyChanged( entityTypeBuilder, newPrimaryKey, previousPrimaryKey, _keyConventionContext); if (_keyConventionContext.ShouldStopProcessing()) { return(_keyConventionContext.Result); } } } if (newPrimaryKey != null && newPrimaryKey.Builder == null) { return(null); } return(newPrimaryKey); }
public abstract IConventionKey OnEntityTypePrimaryKeyChanged( [NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [CanBeNull] IConventionKey newPrimaryKey, [CanBeNull] IConventionKey previousPrimaryKey);
public abstract IConventionRelationshipBuilder OnForeignKeyPropertiesChanged( [NotNull] IConventionRelationshipBuilder relationshipBuilder, [NotNull] IReadOnlyList <IConventionProperty> oldDependentProperties, [NotNull] IConventionKey oldPrincipalKey);
/// <inheritdoc /> public void ProcessKeyRemoved( IConventionEntityTypeBuilder entityTypeBuilder, IConventionKey key, IConventionContext <IConventionKey> _) => Process(entityTypeBuilder);
public abstract IConventionKey OnKeyRemoved([NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] IConventionKey key);
public OnEntityTypePrimaryKeyChangedNode( IConventionEntityTypeBuilder entityTypeBuilder, IConventionKey newPrimaryKey, IConventionKey previousPrimaryKey) { EntityTypeBuilder = entityTypeBuilder; NewPrimaryKey = newPrimaryKey; PreviousPrimaryKey = previousPrimaryKey; }
public override IConventionKey OnKeyRemoved( IConventionEntityTypeBuilder entityTypeBuilder, IConventionKey key) { Add(new OnKeyRemovedNode(entityTypeBuilder, key)); return(key); }
/// <summary> /// Removes a foreign key from this entity type. /// </summary> /// <param name="entityType"> The entity type to remove the foreign key from. </param> /// <param name="properties"> The properties that the foreign key is defined on. </param> /// <param name="principalKey"> The primary or alternate key that is referenced. </param> /// <param name="principalEntityType"> /// The entity type that the relationship targets. This may be different from the type that <paramref name="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). /// </param> /// <returns> The foreign key that was removed. </returns> public static IConventionForeignKey RemoveForeignKey( [NotNull] this IConventionEntityType entityType, [NotNull] IReadOnlyList <IConventionProperty> properties, [NotNull] IConventionKey principalKey, [NotNull] IConventionEntityType principalEntityType) => ((EntityType)entityType).RemoveForeignKey(properties, principalKey, principalEntityType);
public OnKeyRemovedNode(IConventionEntityTypeBuilder entityTypeBuilder, IConventionKey key) { EntityTypeBuilder = entityTypeBuilder; Key = key; }
/// <summary> /// 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. /// </summary> public virtual IConventionKey OnKeyRemoved([NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] IConventionKey key) => _scope.OnKeyRemoved(entityTypeBuilder, key);
/// <summary> /// 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. /// </summary> public virtual IConventionKey?OnKeyRemoved(IConventionEntityTypeBuilder entityTypeBuilder, IConventionKey key) => _scope.OnKeyRemoved(entityTypeBuilder, key);
/// <summary> /// Gets the <see cref="ConfigurationSource" /> for the constraint name. /// </summary> /// <param name="key"> The key. </param> /// <returns> The <see cref="ConfigurationSource" /> for the constraint name. </returns> public static ConfigurationSource?GetNameConfigurationSource([NotNull] this IConventionKey key) => key.FindAnnotation(RelationalAnnotationNames.Name)?.GetConfigurationSource();
/// <summary> /// 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. /// </summary> public virtual IConventionKey OnPrimaryKeyChanged( [NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [CanBeNull] IConventionKey newPrimaryKey, [CanBeNull] IConventionKey previousPrimaryKey) => _scope.OnEntityTypePrimaryKeyChanged(entityTypeBuilder, newPrimaryKey, previousPrimaryKey);
public override IConventionKey?OnKeyRemoved(IConventionEntityTypeBuilder entityTypeBuilder, IConventionKey key) { if (!entityTypeBuilder.Metadata.IsInModel) { return(null); } using (_dispatcher.DelayConventions()) { _keyConventionContext.ResetState(key); foreach (var keyConvention in _conventionSet.KeyRemovedConventions) { keyConvention.ProcessKeyRemoved(entityTypeBuilder, key, _keyConventionContext); if (_keyConventionContext.ShouldStopProcessing()) { return(_keyConventionContext.Result); } } } return(key); }