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 a test for indexes on overlapping FKs #22393

Merged
merged 1 commit into from
Sep 3, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -784,8 +784,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
eb.Property(g => g.Id)
.ValueGeneratedNever();

eb.HasKey(
l => new { l.GameId, l.Id });
eb.HasKey(l => new { l.GameId, l.Id });
});

modelBuilder.Entity<Actor>(
Expand All @@ -794,8 +793,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
eb.Property(g => g.Id)
.ValueGeneratedNever();

eb.HasKey(
a => new { a.GameId, a.Id });
eb.HasKey(a => new { a.GameId, a.Id });

eb.HasOne(a => a.Level)
.WithMany(l => l.Actors)
Expand All @@ -821,8 +819,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
eb.Property(g => g.Id)
.ValueGeneratedNever();

eb.HasKey(
l => new { l.GameId, l.Id });
eb.HasKey(l => new { l.GameId, l.Id });
});

modelBuilder.Entity<Container>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,28 +511,43 @@ public void Removing_relationship_removes_unused_contained_shadow_properties()
[ConditionalFact]
public void Removing_relationship_removes_unused_conventional_index()
{
var modelBuilder = CreateModelBuilder();
var modelBuilder = CreateConventionalModelBuilder();
modelBuilder.Ignore(typeof(SpecialOrder), ConfigurationSource.Explicit);
var principalEntityBuilder = modelBuilder.Entity(typeof(Customer), ConfigurationSource.Explicit);
var derivedPrincipalEntityBuilder = modelBuilder.Entity(typeof(SpecialCustomer), ConfigurationSource.Explicit);
var dependentEntityBuilder = modelBuilder.Entity(typeof(Order), ConfigurationSource.Explicit);

var relationshipBuilder = dependentEntityBuilder.HasRelationship(
principalEntityBuilder.Metadata,
new[] { dependentEntityBuilder.Property(Order.CustomerIdProperty, ConfigurationSource.Convention).Metadata },
ConfigurationSource.Convention);
ConfigurationSource.DataAnnotation);
Assert.NotNull(relationshipBuilder);

var relationshipBuilder2 = dependentEntityBuilder.HasRelationship(
derivedPrincipalEntityBuilder.Metadata,
new[] { dependentEntityBuilder.Property(Order.CustomerIdProperty, ConfigurationSource.Convention).Metadata },
ConfigurationSource.DataAnnotation);
Assert.NotNull(relationshipBuilder2);
Assert.NotSame(relationshipBuilder, relationshipBuilder2);
Assert.Single(dependentEntityBuilder.Metadata.GetIndexes());

Assert.NotNull(
dependentEntityBuilder.HasNoRelationship(relationshipBuilder.Metadata, ConfigurationSource.DataAnnotation));

Assert.Single(dependentEntityBuilder.Metadata.GetIndexes());
Assert.Single(dependentEntityBuilder.Metadata.GetForeignKeys());

Assert.NotNull(
dependentEntityBuilder.HasNoRelationship(relationshipBuilder2.Metadata, ConfigurationSource.DataAnnotation));

Assert.Empty(dependentEntityBuilder.Metadata.GetIndexes());
Assert.Empty(dependentEntityBuilder.Metadata.GetForeignKeys());
}

[ConditionalFact]
// TODO: Add test if the index is being used by another FK when support for multiple FK on same set of properties is added
public void Removing_relationship_does_not_remove_conventional_index_if_in_use()
{
var modelBuilder = CreateModelBuilder();
var modelBuilder = CreateConventionalModelBuilder();
var principalEntityBuilder = modelBuilder.Entity(typeof(Customer), ConfigurationSource.Explicit);
var dependentEntityBuilder = modelBuilder.Entity(typeof(Order), ConfigurationSource.Explicit);

Expand Down Expand Up @@ -3204,13 +3219,15 @@ public void DiscriminatorValue_throws_if_base_cannot_be_set()
Assert.Equal(
CoreStrings.DiscriminatorEntityTypeNotDerived("Splow", "Splot"),
Assert.Throws<InvalidOperationException>(
()
=> discriminatorBuilder.HasValue(nonDerivedTypeBuilder.Metadata, "1")).Message);
() => discriminatorBuilder.HasValue(nonDerivedTypeBuilder.Metadata, "1")).Message);
}

private InternalModelBuilder CreateModelBuilder()
=> new InternalModelBuilder(new Model());

private InternalModelBuilder CreateConventionalModelBuilder()
=> (InternalModelBuilder)InMemoryTestHelpers.Instance.CreateConventionBuilder().GetInfrastructure();

public enum MemberType
{
Property,
Expand Down