Raising Error "The object has been removed from the model." after calling IsRequired() on a Navigation for a modelbuilder entity. #4
Labels
bug
Something isn't working
Microsoft issue
Problem is in VS or EFCore and has been reported.
released
Issue is resolved in a current release
Milestone
When creating an empty database from the generated modelbuilder code an error is raised: "The object has been removed from the model." after calling the IsRequired() method on the navigation builder.
modelBuilder.Entity<global::StrategyCompass.QuickTools.Db.AssetsDb.Model.Entities.AssetCommonDbo>() .HasMany<global::StrategyCompass.QuickTools.Db.AssetsDb.Model.Entities.SubscriberDbo>(p => p.Subscribers) .WithOne(p => p.AssetCommon) .HasForeignKey("AssetCommonId"); modelBuilder.Entity<global::StrategyCompass.QuickTools.Db.AssetsDb.Model.Entities.SubscriberDbo>().Navigation(e => e.AssetCommon).IsRequired();
This issue already occured when bringing the generated code from VS2019/NET5.0 to VS2022/NET6.0 but now it occurs as well after generating the code with the freshly installed rc2 (4.0.0.3).
It occurs for all bidirectional one-to-many relations in the model.
In the meantime I've helped myself with moving the IsRequired() method call to the "HasForeignKey" ReferenceCollectionBuilder in the code line before. This worked for a start, but I'm not shure if does same.
As well I'm not shure, if this issue depends on EF Core issue dotnet/efcore#26611 and will be fixed with EF Core 6.0.1
Thanks.
The text was updated successfully, but these errors were encountered: