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

Most upvoted comments

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:

  • Did you consider testing your code against the pre-release builds?
  • Was there anything blocking you from using pre-release builds?
  • What do you think could make it easier for you to use pre-release builds in the future?

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.