question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ModelBuilder: stackoverflow for may be invalid relationship via fluent api

See original GitHub issue

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 🔥

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:17 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
AndriySvyrydcommented, Sep 12, 2017

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.

2reactions
ajcvickerscommented, Sep 12, 2017

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can not set up one to many relationship with EF fluent API
I am trying to configure a one to many relationship using EF Core via fluent api and i keep getting the following error...
Read more >
What a very bad day at work taught me about building ...
No one agreed with this policy, and they made it known over seemingly hundreds of ... If we write wrong code, we just...
Read more >
Fluent API - Relationships - EF6
Fluent API - Relationships in Entity Framework 6. ... You can then configure foreign key properties by using the HasForeignKey method.
Read more >
Ef core exclude navigation property. NET Web API to explicitly ...
I have been able to use fluent API to get this set up provided that the ... I know using IEnumerable<User> AllCreatedUsers property...
Read more >
Ef core seed large data. Where(m => m. Your migration can ...
You can do this using DbUp, ef migrations, or similar. ... HasData fluent API is part of the so called EF Core Model...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found