efcore: ModelBuilder: stackoverflow for may be invalid relationship via fluent api
Model
public class Blog
{
public int Id { get; set; }
public Blog MyBlog { get; set; }
public Blog InverseBlog { get; set; }
}
// Write following in OnModelCreating method
modelBuilder.Entity<Blog>().HasOne(e => e.MyBlog).WithOne(e => e.InverseBlog).HasForeignKey<Blog>(e => e.Id);
Watch it 🔥
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 17 (11 by maintainers)
Commits related to this issue
- Prevent stack overflow for self-referencing PK-to-PK relationships Fixes #9478 — committed to dotnet/efcore by AndriySvyryd 7 years ago
- Prevent stack overflow for self-referencing PK-to-PK relationships Fixes #9478 — committed to dotnet/efcore by AndriySvyryd 7 years ago
- Prevent stack overflow for self-referencing PK-to-PK relationships Fixes #9478 — committed to dotnet/efcore by AndriySvyryd 7 years ago
Workaround: If you are scaffolding from an existing database you can use the query from https://github.com/aspnet/EntityFrameworkCore/issues/9462#issuecomment-325388454 to find the redundant FKs that cause this issue. Then either drop them or comment out the corresponding navigation properties.
Hi @AlanMacdonald, @Nyami, @dabasejumper, @tandradeflorencio. We are gathering information on the use of EF Core pre-release builds. You reported this issue shortly after the release of 2.0.0 RTM. It would be really helpful if you could let us know:
Thanks in advance for any feedback. Hopefully this will help us to increase the value of pre-release builds going forward.
Tentative schedule for this fix is early October, but that could change.