Skip to content

Commit

Permalink
Fix broken temporal tables tests
Browse files Browse the repository at this point in the history
Looks like this is because the many-to-many data got out of sync with the temporal tables many-to-many configuration, which is overriden to make the tables temporal.

Also, temporal table tests are not running on PRs/C.I., presumably because the SQL Server edition is too old.
  • Loading branch information
ajcvickers committed Sep 16, 2021
1 parent 0b23997 commit 23d6a46
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,26 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
.UsingEntity<Dictionary<string, object>>(
"EntityOneEntityTwo",
r => r.HasOne<EntityTwo>().WithMany().HasForeignKey("EntityTwoId"),
l => l.HasOne<EntityOne>().WithMany().HasForeignKey("EntityOneId")).ToTable(tb => tb.IsTemporal());
l => l.HasOne<EntityOne>().WithMany().HasForeignKey("EntityOneId"))
.ToTable(tb => tb.IsTemporal());

// Nav:2 Payload:No Join:Concrete Extra:None
modelBuilder.Entity<EntityOne>()
.HasMany(e => e.TwoSkip)
.WithMany(e => e.OneSkip)
.UsingEntity<JoinOneToTwo>(
r => r.HasOne(e => e.Two).WithMany().HasForeignKey(e => e.TwoId),
l => l.HasOne(e => e.One).WithMany().HasForeignKey(e => e.OneId)).ToTable(tb => tb.IsTemporal());
l => l.HasOne(e => e.One).WithMany().HasForeignKey(e => e.OneId))
.ToTable(tb => tb.IsTemporal());

// Nav:6 Payload:Yes Join:Concrete Extra:None
modelBuilder.Entity<EntityOne>()
.HasMany(e => e.ThreeSkipPayloadFull)
.WithMany(e => e.OneSkipPayloadFull)
.UsingEntity<JoinOneToThreePayloadFull>(
r => r.HasOne(x => x.Three).WithMany(e => e.JoinOnePayloadFull),
l => l.HasOne(x => x.One).WithMany(e => e.JoinThreePayloadFull)).ToTable(tb => tb.IsTemporal());
l => l.HasOne(x => x.One).WithMany(e => e.JoinThreePayloadFull))
.ToTable(tb => tb.IsTemporal());

// Nav:4 Payload:Yes Join:Shared Extra:None
modelBuilder.Entity<EntityOne>()
Expand All @@ -85,7 +88,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
.UsingEntity<Dictionary<string, object>>(
"JoinOneToThreePayloadFullShared",
r => r.HasOne<EntityThree>().WithMany(e => e.JoinOnePayloadFullShared).HasForeignKey("ThreeId"),
l => l.HasOne<EntityOne>().WithMany(e => e.JoinThreePayloadFullShared).HasForeignKey("OneId")).ToTable(tb => tb.IsTemporal())
l => l.HasOne<EntityOne>().WithMany(e => e.JoinThreePayloadFullShared).HasForeignKey("OneId"))
.ToTable(tb => tb.IsTemporal())
.IndexerProperty<string>("Payload");

// Nav:6 Payload:Yes Join:Concrete Extra:Self-Ref
Expand All @@ -94,15 +98,17 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
.WithMany(e => e.SelfSkipPayloadRight)
.UsingEntity<JoinOneSelfPayload>(
l => l.HasOne(x => x.Left).WithMany(x => x.JoinSelfPayloadLeft),
r => r.HasOne(x => x.Right).WithMany(x => x.JoinSelfPayloadRight)).ToTable(tb => tb.IsTemporal());
r => r.HasOne(x => x.Right).WithMany(x => x.JoinSelfPayloadRight))
.ToTable(tb => tb.IsTemporal());

// Nav:2 Payload:No Join:Concrete Extra:Inheritance
modelBuilder.Entity<EntityOne>()
.HasMany(e => e.BranchSkip)
.WithMany(e => e.OneSkip)
.UsingEntity<JoinOneToBranch>(
r => r.HasOne<EntityBranch>().WithMany(),
l => l.HasOne<EntityOne>().WithMany()).ToTable(tb => tb.IsTemporal());
l => l.HasOne<EntityOne>().WithMany())
.ToTable(tb => tb.IsTemporal());

modelBuilder.Entity<EntityTwo>()
.HasOne(e => e.Reference)
Expand All @@ -120,28 +126,30 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
.WithMany(e => e.TwoSkipFull)
.UsingEntity<JoinTwoToThree>(
r => r.HasOne(x => x.Three).WithMany(e => e.JoinTwoFull),
l => l.HasOne(x => x.Two).WithMany(e => e.JoinThreeFull)).ToTable(tb => tb.IsTemporal());
l => l.HasOne(x => x.Two).WithMany(e => e.JoinThreeFull))
.ToTable(tb => tb.IsTemporal());

// Nav:2 Payload:No Join:Shared Extra:Self-ref
// TODO: Remove UsingEntity
modelBuilder.Entity<EntityTwo>()
.HasMany(e => e.SelfSkipSharedLeft)
.WithMany(e => e.SelfSkipSharedRight)
.UsingEntity<Dictionary<string, object>>(
"JoinTwoSelfShared",
l => l.HasOne<EntityTwo>().WithMany().HasForeignKey("LeftId"),
r => r.HasOne<EntityTwo>().WithMany().HasForeignKey("RightId")).ToTable(tb => tb.IsTemporal());
"EntityTwoEntityTwo",
l => l.HasOne<EntityTwo>().WithMany().HasForeignKey("SelfSkipSharedLeftId"),
r => r.HasOne<EntityTwo>().WithMany().HasForeignKey("SelfSkipSharedRightId"))
.ToTable(tb => tb.IsTemporal());

// Nav:2 Payload:No Join:Shared Extra:CompositeKey
// TODO: Remove UsingEntity
modelBuilder.Entity<EntityTwo>()
.HasMany(e => e.CompositeKeySkipShared)
.WithMany(e => e.TwoSkipShared)
.UsingEntity<Dictionary<string, object>>(
"JoinTwoToCompositeKeyShared",
r => r.HasOne<EntityCompositeKey>().WithMany().HasForeignKey("CompositeId1", "CompositeId2", "CompositeId3"),
l => l.HasOne<EntityTwo>().WithMany().HasForeignKey("TwoId")).ToTable(tb => tb.IsTemporal())
.HasKey("TwoId", "CompositeId1", "CompositeId2", "CompositeId3");
"EntityCompositeKeyEntityTwo",
r => r.HasOne<EntityCompositeKey>().WithMany()
.HasForeignKey("CompositeKeySkipSharedKey1", "CompositeKeySkipSharedKey2", "CompositeKeySkipSharedKey3"),
l => l.HasOne<EntityTwo>().WithMany().HasForeignKey("TwoSkipSharedId"))
.ToTable(tb => tb.IsTemporal())
.HasKey("TwoSkipSharedId", "CompositeKeySkipSharedKey1", "CompositeKeySkipSharedKey2", "CompositeKeySkipSharedKey3");

// Nav:6 Payload:No Join:Concrete Extra:CompositeKey
modelBuilder.Entity<EntityThree>()
Expand All @@ -155,26 +163,28 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
e.CompositeId2,
e.CompositeId3
}).IsRequired(),
r => r.HasOne(x => x.Three).WithMany(x => x.JoinCompositeKeyFull).IsRequired()).ToTable(tb => tb.IsTemporal());
r => r.HasOne(x => x.Three).WithMany(x => x.JoinCompositeKeyFull).IsRequired())
.ToTable(tb => tb.IsTemporal());

// Nav:2 Payload:No Join:Shared Extra:Inheritance
// TODO: Remove UsingEntity
modelBuilder.Entity<EntityThree>().HasMany(e => e.RootSkipShared).WithMany(e => e.ThreeSkipShared)
.UsingEntity<Dictionary<string, object>>(
"EntityRootEntityThree",
r => r.HasOne<EntityRoot>().WithMany().HasForeignKey("EntityRootId"),
l => l.HasOne<EntityThree>().WithMany().HasForeignKey("EntityThreeId")).ToTable(tb => tb.IsTemporal());
r => r.HasOne<EntityRoot>().WithMany().HasForeignKey("RootSkipSharedId"),
l => l.HasOne<EntityThree>().WithMany().HasForeignKey("ThreeSkipSharedId"))
.ToTable(tb => tb.IsTemporal());

// Nav:2 Payload:No Join:Shared Extra:Inheritance,CompositeKey
// TODO: Remove UsingEntity
modelBuilder.Entity<EntityCompositeKey>()
.HasMany(e => e.RootSkipShared)
.WithMany(e => e.CompositeKeySkipShared)
.UsingEntity<Dictionary<string, object>>(
"JoinCompositeKeyToRootShared",
r => r.HasOne<EntityRoot>().WithMany().HasForeignKey("RootId"),
l => l.HasOne<EntityCompositeKey>().WithMany().HasForeignKey("CompositeId1", "CompositeId2", "CompositeId3")).ToTable(tb => tb.IsTemporal())
.HasKey("CompositeId1", "CompositeId2", "CompositeId3", "RootId");
"EntityCompositeKeyEntityRoot",
r => r.HasOne<EntityRoot>().WithMany().HasForeignKey("RootSkipSharedId"),
l => l.HasOne<EntityCompositeKey>().WithMany()
.HasForeignKey("CompositeKeySkipSharedKey1", "CompositeKeySkipSharedKey2", "CompositeKeySkipSharedKey3"))
.ToTable(tb => tb.IsTemporal())
.HasKey("CompositeKeySkipSharedKey1", "CompositeKeySkipSharedKey2", "CompositeKeySkipSharedKey3", "RootSkipSharedId");

// Nav:6 Payload:No Join:Concrete Extra:Inheritance,CompositeKey
modelBuilder.Entity<EntityCompositeKey>()
Expand All @@ -188,7 +198,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
e.CompositeId1,
e.CompositeId2,
e.CompositeId3
})).ToTable(tb => tb.IsTemporal())
}))
.ToTable(tb => tb.IsTemporal())
.HasKey(
e => new
{
Expand Down Expand Up @@ -230,15 +241,15 @@ protected override void Seed(ManyToManyContext context)
("EntityRootEntityThree", "EntityRootEntityThreeHistory"),

("JoinCompositeKeyToLeaf", "JoinCompositeKeyToLeafHistory"),
("JoinCompositeKeyToRootShared", "JoinCompositeKeyToRootSharedHistory"),
("EntityCompositeKeyEntityRoot", "EntityCompositeKeyEntityRootHistory"),
("JoinOneSelfPayload", "JoinOneSelfPayloadHistory"),
("JoinOneToBranch", "JoinOneToBranchHistory"),
("JoinOneToThreePayloadFull", "JoinOneToThreePayloadFullHistory"),
("JoinOneToThreePayloadFullShared", "JoinOneToThreePayloadFullSharedHistory"),
("JoinOneToTwo", "JoinOneToTwoHistory"),
("JoinThreeToCompositeKeyFull", "JoinThreeToCompositeKeyFullHistory"),
("JoinTwoSelfShared", "JoinTwoSelfSharedHistory"),
("JoinTwoToCompositeKeyShared", "JoinTwoToCompositeKeySharedHistory"),
("EntityTwoEntityTwo", "EntityTwoEntityTwoHistory"),
("EntityCompositeKeyEntityTwo", "EntityCompositeKeyEntityTwoHistory"),
("JoinTwoToThree", "JoinTwoToThreeHistory"),
};

Expand Down
Loading

0 comments on commit 23d6a46

Please sign in to comment.