Skip to content

Commit

Permalink
Move InternalEntityTypeBuilder state to EntityType
Browse files Browse the repository at this point in the history
Part of #3476
  • Loading branch information
AndriySvyryd committed Nov 9, 2015
1 parent bd89d1a commit e8b1d9c
Show file tree
Hide file tree
Showing 33 changed files with 682 additions and 731 deletions.
4 changes: 1 addition & 3 deletions src/EntityFramework.Core/EntityFramework.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@
<Compile Include="Metadata\IMutableNavigation.cs" />
<Compile Include="Metadata\IMutableProperty.cs" />
<Compile Include="Metadata\Internal\InternalMetadataBuilder`.cs" />
<Compile Include="Metadata\Internal\MetadataHelper.cs" />
<Compile Include="Extensions\MutableEntityTypeExtensions.cs" />
<Compile Include="Extensions\MutableKeyExtensions.cs" />
<Compile Include="Extensions\MutableModelExtensions.cs" />
Expand Down Expand Up @@ -343,7 +342,6 @@
<Compile Include="Metadata\Internal\InternalModelBuilder.cs" />
<Compile Include="Metadata\Internal\InternalPropertyBuilder.cs" />
<Compile Include="Metadata\Internal\InternalRelationshipBuilder.cs" />
<Compile Include="Metadata\Internal\MetadataDictionary.cs" />
<Compile Include="Infrastructure\TypedAnnotation.cs" />
<Compile Include="Query\ExpressionVisitors\EntityQueryableExpressionVisitor.cs" />
<Compile Include="Query\ExpressionVisitors\Internal\DefaultQueryExpressionVisitor.cs" />
Expand Down Expand Up @@ -493,4 +491,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ public virtual bool Apply(InternalPropertyBuilder propertyBuilder)
{
foreach (var foreignKey in propertyBuilder.Metadata.FindContainingForeignKeys())
{
Apply(propertyBuilder.ModelBuilder.Entity(foreignKey.DeclaringEntityType.Name, ConfigurationSource.Convention)
.Relationship(foreignKey, ConfigurationSource.Convention));
Apply(foreignKey.Builder);
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,19 +260,15 @@ public virtual InternalPropertyBuilder Apply(InternalPropertyBuilder propertyBui
if (!((IProperty)(propertyBuilder.Metadata)).IsShadowProperty)
{
var entityType = propertyBuilder.Metadata.DeclaringEntityType;
var entityTypeBuilder = propertyBuilder.ModelBuilder.Entity(entityType.Name, ConfigurationSource.Convention);

foreach (var foreignKey in entityType.GetDeclaredForeignKeys().ToList())
foreach (var foreignKey in entityType.GetDeclaredForeignKeys().Concat(entityType.GetDerivedForeignKeys()).ToList())
{
var relationshipBuilder = entityTypeBuilder.Relationship(foreignKey, ConfigurationSource.Convention);
Apply(relationshipBuilder);
Apply(foreignKey.Builder);
}

foreach (var foreignKey in entityType.GetReferencingForeignKeys().ToList())
{
var relationshipBuilder = propertyBuilder.ModelBuilder
.Entity(foreignKey.DeclaringEntityType.Name, ConfigurationSource.Convention)
.Relationship(foreignKey, ConfigurationSource.Convention);
Apply(relationshipBuilder);
Apply(foreignKey.Builder);
}
}
return propertyBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@ private static bool CanMergeWith(
var fk = existingNavigation.ForeignKey;
return (fk.IsSelfReferencing()
|| fk.ResolveOtherEntityType(existingNavigation.DeclaringEntityType) == inverseEntityTypeBuilder.Metadata)
&& inverseEntityTypeBuilder.ModelBuilder.Entity(fk.DeclaringEntityType.Name, ConfigurationSource.Convention)
.Relationship(fk, ConfigurationSource.Convention)
.CanSetNavigation(inverseName, !existingNavigation.IsDependentToPrincipal(), ConfigurationSource.Convention);
&& fk.Builder.CanSetNavigation(inverseName, !existingNavigation.IsDependentToPrincipal(), ConfigurationSource.Convention);
}

private IReadOnlyList<RelationshipCandidate> RemoveInheritedInverseNavigations(
Expand Down Expand Up @@ -333,6 +331,12 @@ public virtual bool Apply(
InternalEntityTypeBuilder targetEntityTypeBuilder,
string navigationName)
{
sourceEntityTypeBuilder = sourceEntityTypeBuilder.ModelBuilder.Entity(sourceEntityTypeBuilder.Metadata.Name, ConfigurationSource.Convention);
if (sourceEntityTypeBuilder == null)
{
return true;
}

if (sourceEntityTypeBuilder.IsIgnored(navigationName, ConfigurationSource.Convention))
{
return true;
Expand Down
Loading

0 comments on commit e8b1d9c

Please sign in to comment.