Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor ConventionScope #19297

Merged
merged 2 commits into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/EFCore/Metadata/Builders/OwnedNavigationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ protected virtual InternalRelationshipBuilder Builder
[EntityFrameworkInternal]
protected virtual T UpdateBuilder<T>([NotNull] Func<T> configure)
{
var foreignKey = _builder.Metadata;
IConventionForeignKey foreignKey = _builder.Metadata;
var result = DependentEntityType.Model.ConventionDispatcher.Run(configure, ref foreignKey);
if (foreignKey != null)
{
_builder = foreignKey.Builder;
_builder = ((ForeignKey)foreignKey).Builder;
}

return result;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal
{
public partial class ConventionDispatcher
{
private abstract class ConventionNode
{
public abstract void Run(ConventionDispatcher dispatcher);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Reflection;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal
{
public partial class ConventionDispatcher
{
private abstract class ConventionScope : ConventionNode
{
public virtual ConventionScope Parent => null;
public virtual IReadOnlyList<ConventionNode> Children => null;

public int GetLeafCount()
{
if (Children == null)
{
return 0;
}

var scopesToVisit = new Queue<ConventionScope>();
scopesToVisit.Enqueue(this);
var leafCount = 0;
while (scopesToVisit.Count > 0)
{
var scope = scopesToVisit.Dequeue();
if (scope.Children == null)
{
continue;
}

foreach (var conventionNode in scope.Children)
{
if (conventionNode is ConventionScope nextScope)
{
scopesToVisit.Enqueue(nextScope);
}
else
{
leafCount++;
}
}
}

return leafCount;
}

public abstract IConventionEntityTypeBuilder OnEntityTypeAdded([NotNull] IConventionEntityTypeBuilder entityTypeBuilder);

public abstract IConventionAnnotation OnEntityTypeAnnotationChanged(
[NotNull] IConventionEntityTypeBuilder entityTypeBuilder,
[NotNull] string name,
[CanBeNull] IConventionAnnotation annotation,
[CanBeNull] IConventionAnnotation oldAnnotation);

public abstract IConventionEntityType OnEntityTypeBaseTypeChanged(
[NotNull] IConventionEntityTypeBuilder entityTypeBuilder,
[CanBeNull] IConventionEntityType newBaseType,
[CanBeNull] IConventionEntityType previousBaseType);

public abstract string OnEntityTypeIgnored(
[NotNull] IConventionModelBuilder modelBuilder, [NotNull] string name, [CanBeNull] Type type);

public abstract string OnEntityTypeMemberIgnored([NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] string name);

public abstract IConventionKey OnEntityTypePrimaryKeyChanged(
[NotNull] IConventionEntityTypeBuilder entityTypeBuilder,
[CanBeNull] IConventionKey newPrimaryKey,
[CanBeNull] IConventionKey previousPrimaryKey);

public abstract IConventionEntityType OnEntityTypeRemoved(
[NotNull] IConventionModelBuilder modelBuilder, [NotNull] IConventionEntityType entityType);

public abstract IConventionRelationshipBuilder OnForeignKeyAdded([NotNull] IConventionRelationshipBuilder relationshipBuilder);

public abstract IConventionAnnotation OnForeignKeyAnnotationChanged(
[NotNull] IConventionRelationshipBuilder relationshipBuilder,
[NotNull] string name,
[CanBeNull] IConventionAnnotation annotation,
[CanBeNull]IConventionAnnotation oldAnnotation);

public abstract IConventionRelationshipBuilder OnForeignKeyOwnershipChanged(
[NotNull] IConventionRelationshipBuilder relationshipBuilder);

public abstract IConventionRelationshipBuilder OnForeignKeyPrincipalEndChanged(
[NotNull] IConventionRelationshipBuilder relationshipBuilder);

public abstract IConventionRelationshipBuilder OnForeignKeyPropertiesChanged(
[NotNull] IConventionRelationshipBuilder relationshipBuilder,
[NotNull] IReadOnlyList<IConventionProperty> oldDependentProperties,
[NotNull] IConventionKey oldPrincipalKey);

public abstract IConventionForeignKey OnForeignKeyRemoved(
[NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] IConventionForeignKey foreignKey);

public abstract IConventionRelationshipBuilder OnForeignKeyRequirednessChanged(
[NotNull] IConventionRelationshipBuilder relationshipBuilder);

public abstract IConventionRelationshipBuilder OnForeignKeyUniquenessChanged(
[NotNull] IConventionRelationshipBuilder relationshipBuilder);

public abstract IConventionIndexBuilder OnIndexAdded([NotNull] IConventionIndexBuilder indexBuilder);

public abstract IConventionAnnotation OnIndexAnnotationChanged(
[NotNull] IConventionIndexBuilder indexBuilder,
[NotNull] string name,
[CanBeNull] IConventionAnnotation annotation,
[CanBeNull] IConventionAnnotation oldAnnotation);

public abstract IConventionIndex OnIndexRemoved(
[NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] IConventionIndex index);

public abstract IConventionIndexBuilder OnIndexUniquenessChanged([NotNull] IConventionIndexBuilder indexBuilder);
public abstract IConventionKeyBuilder OnKeyAdded([NotNull] IConventionKeyBuilder keyBuilder);

public abstract IConventionAnnotation OnKeyAnnotationChanged(
[NotNull] IConventionKeyBuilder keyBuilder,
[NotNull] string name,
[CanBeNull] IConventionAnnotation annotation,
[CanBeNull] IConventionAnnotation oldAnnotation);

public abstract IConventionKey OnKeyRemoved([NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] IConventionKey key);

public abstract IConventionAnnotation OnModelAnnotationChanged(
[NotNull] IConventionModelBuilder modelBuilder,
[NotNull] string name,
[CanBeNull] IConventionAnnotation annotation,
[CanBeNull] IConventionAnnotation oldAnnotation);

public abstract IConventionNavigation OnNavigationAdded(
[NotNull] IConventionRelationshipBuilder relationshipBuilder, [NotNull] IConventionNavigation navigation);

public abstract string OnNavigationRemoved(
[NotNull] IConventionEntityTypeBuilder sourceEntityTypeBuilder,
[NotNull] IConventionEntityTypeBuilder targetEntityTypeBuilder,
[NotNull] string navigationName,
[CanBeNull] MemberInfo memberInfo);

public abstract IConventionPropertyBuilder OnPropertyAdded([NotNull] IConventionPropertyBuilder propertyBuilder);

public abstract IConventionAnnotation OnPropertyAnnotationChanged(
[NotNull] IConventionPropertyBuilder propertyBuilder,
[NotNull] string name,
[CanBeNull] IConventionAnnotation annotation,
[CanBeNull] IConventionAnnotation oldAnnotation);

public abstract FieldInfo OnPropertyFieldChanged(
[NotNull] IConventionPropertyBuilder propertyBuilder, FieldInfo newFieldInfo, [CanBeNull] FieldInfo oldFieldInfo);

public abstract IConventionPropertyBuilder OnPropertyNullableChanged([NotNull] IConventionPropertyBuilder propertyBuilder);
}
}
}
Loading