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

Add more overloads of UsingEntity() #25357

Merged
merged 1 commit into from
Jul 30, 2021
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
385 changes: 290 additions & 95 deletions src/EFCore/Metadata/Builders/CollectionCollectionBuilder.cs

Large diffs are not rendered by default.

302 changes: 219 additions & 83 deletions src/EFCore/Metadata/Builders/CollectionCollectionBuilder`.cs

Large diffs are not rendered by default.

25 changes: 0 additions & 25 deletions src/EFCore/Metadata/Builders/CollectionNavigationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,34 +239,9 @@ public virtual CollectionCollectionBuilder WithMany(string navigationName)
WithLeftManyNavigation(navigationName),
WithRightManyNavigation(navigationName, leftName!));

Configure(collectionCollectionBuilder);

return collectionCollectionBuilder;
}

/// <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>
[EntityFrameworkInternal]
protected virtual void Configure(CollectionCollectionBuilder collectionCollectionBuilder)
{
Check.NotNull(collectionCollectionBuilder, nameof(collectionCollectionBuilder));

var leftSkipNavigation = (SkipNavigation)collectionCollectionBuilder.LeftNavigation;
var rightSkipNavigation = (SkipNavigation)collectionCollectionBuilder.RightNavigation;

leftSkipNavigation.Builder.HasInverse(rightSkipNavigation, ConfigurationSource.Explicit);

// Note: we delayed setting the ConfigurationSource of SkipNavigation
// in HasMany(). But now we know that both skip navigations should
// have ConfigurationSource.Explicit.
leftSkipNavigation.UpdateConfigurationSource(ConfigurationSource.Explicit);
rightSkipNavigation.UpdateConfigurationSource(ConfigurationSource.Explicit);
}

/// <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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,11 @@ public CollectionNavigationBuilder(
/// <returns> An object to further configure the relationship. </returns>
public new virtual ReferenceCollectionBuilder<TEntity, TRelatedEntity> WithOne(
string? navigationName = null)
{
return new(
=> new(
DeclaringEntityType,
RelatedEntityType,
WithOneBuilder(
Check.NullButNotEmpty(navigationName, nameof(navigationName))).Metadata);
}

/// <summary>
/// <para>
Expand Down Expand Up @@ -102,8 +100,6 @@ public virtual ReferenceCollectionBuilder<TEntity, TRelatedEntity> WithOne(
WithLeftManyNavigation(navigationName),
WithRightManyNavigation(navigationName, leftName!));

Configure(collectionCollectionBuilder);

return collectionCollectionBuilder;
}

Expand Down Expand Up @@ -138,8 +134,6 @@ public virtual CollectionCollectionBuilder<TRelatedEntity, TEntity> WithMany(
WithLeftManyNavigation(navigationExpression.GetMemberAccess()),
WithRightManyNavigation(navigationExpression.GetMemberAccess(), leftName));

Configure(collectionCollectionBuilder);

return collectionCollectionBuilder;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,10 @@ public virtual void ProcessSkipNavigationRemoved(
private void CreateJoinEntityType(IConventionSkipNavigationBuilder skipNavigationBuilder)
{
var skipNavigation = (SkipNavigation)skipNavigationBuilder.Metadata;
if (skipNavigation.ForeignKey != null
|| !skipNavigation.IsCollection)
{
return;
}

var inverseSkipNavigation = skipNavigation.Inverse;
if (inverseSkipNavigation == null
if (skipNavigation.ForeignKey != null
|| !skipNavigation.IsCollection
|| inverseSkipNavigation == null
|| inverseSkipNavigation.ForeignKey != null
|| !inverseSkipNavigation.IsCollection)
{
Expand All @@ -120,7 +116,7 @@ private void CreateJoinEntityType(IConventionSkipNavigationBuilder skipNavigatio

if (model.FindEntityType(joinEntityTypeName) != null)
{
var otherIdentifiers = model.GetEntityTypes().ToDictionary(et => et.Name, et => 0);
var otherIdentifiers = model.GetEntityTypes().ToDictionary(et => et.Name, _ => 0);
joinEntityTypeName = Uniquifier.Uniquify(
joinEntityTypeName,
otherIdentifiers,
Expand All @@ -131,24 +127,13 @@ private void CreateJoinEntityType(IConventionSkipNavigationBuilder skipNavigatio
joinEntityTypeName, Model.DefaultPropertyBagType, ConfigurationSource.Convention)!;

var leftForeignKey = CreateSkipNavigationForeignKey(skipNavigation, joinEntityTypeBuilder);
if (leftForeignKey == null)
{
model.Builder.HasNoEntityType(joinEntityTypeBuilder.Metadata, ConfigurationSource.Convention);
return;
}

var rightForeignKey = CreateSkipNavigationForeignKey(inverseSkipNavigation, joinEntityTypeBuilder);
if (rightForeignKey == null)
{
model.Builder.HasNoEntityType(joinEntityTypeBuilder.Metadata, ConfigurationSource.Convention);
return;
}

skipNavigation.Builder.HasForeignKey(leftForeignKey, ConfigurationSource.Convention);
inverseSkipNavigation.Builder.HasForeignKey(rightForeignKey, ConfigurationSource.Convention);
}

private static ForeignKey? CreateSkipNavigationForeignKey(
private static ForeignKey CreateSkipNavigationForeignKey(
SkipNavigation skipNavigation,
InternalEntityTypeBuilder joinEntityTypeBuilder)
=> joinEntityTypeBuilder
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Metadata/Internal/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class Model : ConventionAnnotatable, IMutableModel, IConventionModel, IRu
private readonly Dictionary<string, ConfigurationSource> _ignoredTypeNames = new(StringComparer.Ordinal);
private Dictionary<string, ConfigurationSource>? _ownedTypes;
private readonly Dictionary<Type, (ConfigurationSource ConfigurationSource, SortedSet<EntityType> Types)> _sharedTypes =
new() { { DefaultPropertyBagType, (ConfigurationSource.Convention, new SortedSet<EntityType>(EntityTypeFullNameComparer.Instance)) } };
new() { { DefaultPropertyBagType, (ConfigurationSource.Explicit, new SortedSet<EntityType>(EntityTypeFullNameComparer.Instance)) } };

private ConventionDispatcher? _conventionDispatcher;
private IList<IModelFinalizedConvention>? _modelFinalizedConventions;
Expand Down
Loading