Skip to content
New issue

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

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

Already on GitHub? # to your account

Temporal Tables: The given key 'SqlServer:TemporalHistoryTableName' was not present in the dictionary when creating migration on entity mapped to temporal table without explicitly providing history table name #25511

Closed
maumar opened this issue Aug 13, 2021 · 1 comment · Fixed by #25512
Assignees
Labels
area-query area-temporal-tables closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@maumar
Copy link
Contributor

maumar commented Aug 13, 2021

Found by @benjaminsaljooghi

problem happens when trying to create migrations for model containing entity mapped to temporal table, if the history table is not explicitly specified, e.g.

modelBuilder.Entity<Student>().ToTable(tb => tb.IsTemporal());

exception:

System.Collections.Generic.KeyNotFoundException: The given key 'SqlServer:TemporalHistoryTableName' was not present in the dictionary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key) in System.Private.CoreLib.dll:token 0x600675e+0x17
   at Microsoft.EntityFrameworkCore.SqlServer.Design.Internal.SqlServerAnnotationCodeGenerator.GenerateFluentApiCalls(IEntityType entityType, IDictionary`2 annotations) in Microsoft.EntityFrameworkCore.SqlServer.dll:token 0x60004c2+0x45
   at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateEntityTypeAnnotations(String builderName, IEntityType entityType, IndentedStringBuilder stringBuilder) in Microsoft.EntityFrameworkCore.Design.dll:token 0x600032b+0x67d
   at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateEntityType(String builderName, IEntityType entityType, IndentedStringBuilder stringBuilder) in Microsoft.EntityFrameworkCore.Design.dll:token 0x600031a+0x1bd
   at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateEntityTypes(String builderName, IReadOnlyList`1 entityTypes, IndentedStringBuilder stringBuilder) in Microsoft.EntityFrameworkCore.Design.dll:token 0x6000319+0x5f
   at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationsGenerator.GenerateMetadata(String migrationNamespace, Type contextType, String migrationName, String migrationId, IModel targetModel) in Microsoft.EntityFrameworkCore.Design.dll:token 0x6000302+0x208
   at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace, String language) in Microsoft.EntityFrameworkCore.Design.dll:token 0x600038c+0x2b3
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace) in Microsoft.EntityFrameworkCore.Design.dll:token 0x6000474+0xa5
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace) in Microsoft.EntityFrameworkCore.Design.dll:token 0x60003e5+0xc
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0() in Microsoft.EntityFrameworkCore.Design.dll:token 0x60006df+0x0
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0() in Microsoft.EntityFrameworkCore.Design.dll:token 0x60006f3+0x0
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action) in Microsoft.EntityFrameworkCore.Design.dll:token 0x600066a+0xc
@maumar maumar self-assigned this Aug 13, 2021
@maumar maumar added this to the 6.0.0 milestone Aug 13, 2021
@maumar
Copy link
Contributor Author

maumar commented Aug 13, 2021

Workaround: specify history table name

modelBuilder.Entity<Student>().ToTable(tb => tb.IsTemporal(ttb => ttb.WithHistoryTable("StudentHistory")));

maumar added a commit that referenced this issue Aug 13, 2021
…toryTableName' was not present in the dictionary when creating migration on entity mapped to temporal table without explicitly providing history table name

Problem was that we don't store the default history table name in the annotation (like we do with default period property names), instead the getter on IReadOnlyEntityType retrieves the default value if needed.

Fix is to check if the history table annotation is present in the annotation list, just like we do with the history table schema.
maumar added a commit that referenced this issue Aug 13, 2021
…toryTableName' was not present in the dictionary when creating migration on entity mapped to temporal table without explicitly providing history table name

Problem was that we don't store the default history table name in the annotation (like we do with default period property names), instead the getter on IReadOnlyEntityType retrieves the default value if needed.

Fix is to check if the history table annotation is present in the annotation list, just like we do with the history table schema.

Fixes #25511
@maumar maumar added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Aug 13, 2021
maumar added a commit that referenced this issue Aug 13, 2021
…toryTableName' was not present in the dictionary when creating migration on entity mapped to temporal table without explicitly providing history table name

Problem was that we don't store the default history table name in the annotation (like we do with default period property names), instead the getter on IReadOnlyEntityType retrieves the default value if needed.

Fix is to check if the history table annotation is present in the annotation list, just like we do with the history table schema.

Fixes #25511
maumar added a commit that referenced this issue Aug 13, 2021
…toryTableName' was not present in the dictionary when creating migration on entity mapped to temporal table without explicitly providing history table name

Problem was that we don't store the default history table name in the annotation (like we do with default period property names), instead the getter on IReadOnlyEntityType retrieves the default value if needed.

Fix is to check if the history table annotation is present in the annotation list, just like we do with the history table schema.

Fixes #25511
@maumar maumar closed this as completed in b3619b4 Aug 14, 2021
@ajcvickers ajcvickers modified the milestones: 6.0.0, 6.0.0-rc1 Aug 14, 2021
@ajcvickers ajcvickers modified the milestones: 6.0.0-rc1, 6.0.0 Nov 8, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment