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

Raising Error "The object has been removed from the model." after calling IsRequired() on a Navigation for a modelbuilder entity. #4

Closed
Kalle4242 opened this issue Dec 7, 2021 · 0 comments
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

Comments

@Kalle4242
Copy link

Kalle4242 commented Dec 7, 2021

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.

@msawczyn msawczyn added bug Something isn't working pending release Issue is resolved in the current codebase, will be published with the next release Microsoft issue Problem is in VS or EFCore and has been reported. labels Dec 7, 2021
@msawczyn msawczyn added this to the 4.0.0 milestone Dec 7, 2021
@msawczyn msawczyn removed the pending release Issue is resolved in the current codebase, will be published with the next release label Dec 7, 2021
@msawczyn msawczyn added pending release Issue is resolved in the current codebase, will be published with the next release in preview The issue is resolved in a currently-published preview release and removed pending release Issue is resolved in the current codebase, will be published with the next release labels Dec 8, 2021
@msawczyn msawczyn added released Issue is resolved in a current release and removed in preview The issue is resolved in a currently-published preview release labels Dec 19, 2021
@msawczyn msawczyn reopened this Dec 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

2 participants