dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.72k stars 3.17k forks source link

TPH inheritance: subclasses with shared properties #4703

Closed rok7 closed 2 years ago

rok7 commented 8 years ago

Hello

I'm struggling with the problem which has been described (and solved) for EF6 at http://entityframework.codeplex.com/workitem/583

When creating a migration I get the exception "Element with the same key has already been added" (full stack below). Is there a workaround other than moving all shared properties to the base class or multiply the properties with sligtly different names?

Regards rok

PM> dnx ef migrations add MySchema System.ArgumentException: Ein Element mit dem gleichen Schlssel wurde bereits hinzugefgt. bei System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) bei System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) bei Microsoft.Data.Entity.Migrations.Design.CSharpMigrationOperationGenerator.Generate(CreateTableOperation operation, IndentedStringBuilder builder) bei CallSite.Target(Closure , CallSite , CSharpMigrationOperationGenerator , Object , IndentedStringBuilder ) bei Microsoft.Data.Entity.Migrations.Design.CSharpMigrationOperationGenerator.Generate(String builderName, IReadOnlyList1 operations, IndentedStringBuilder builder) bei Microsoft.Data.Entity.Migrations.Design.CSharpMigrationsGenerator.GenerateMigration(String migrationNamespace, String migrationName, IReadOnlyList1 upOperations, IReadOnlyList1 downOperations) bei Microsoft.Data.Entity.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace) bei Microsoft.Data.Entity.Design.MigrationsOperations.AddMigration(String name, String outputDir, String contextType) bei Microsoft.Data.Entity.Commands.Program.Executor.<>c__DisplayClass6_0.b__0() bei Microsoft.Data.Entity.Commands.Program.Executor.Execute(Action action) Ein Element mit dem gleichen Schlssel wurde bereits hinzugefgt.

rowanmiller commented 8 years ago

Possibly a dupe of https://github.com/aspnet/EntityFramework/issues/4522

@rok7 can you provide a code listing (or project) we can run to reproduce this issue. In general, the scenario is supported, so there must be something specific in your model.

rok7 commented 8 years ago

Hello Rowan

Here's a minimal project to reproduce the issue. Please contact me if you need more information.

Thank you Roland

Am 08.03.2016 um 19:33 schrieb Rowan Miller:

Possibly a dupe of #4522 https://github.com/aspnet/EntityFramework/issues/4522

@rok7 https://github.com/rok7 can you provide a code listing (or project) we can run to reproduce this issue. In general, the scenario is supported, so there must be something specific in your model.

— Reply to this email directly or view it on GitHub https://github.com/aspnet/EntityFramework/issues/4703#issuecomment-193904945.

rowanmiller commented 8 years ago

@rok7 think you forgot to attach it?

rok7 commented 8 years ago

Sorry, here's another try. WebApplication2.zip

AndriySvyryd commented 8 years ago

This doesn't repro with the latest bits, so it was probably fixed.