I have a scenario I haven’t seen before and I can’t seem to find an answer on it. Could be improper configuration or something else.
I have two tables in a mysql database, one table is called Teams and another table is called TeamStats, in a one to many relationship with foreign keys, below are a short version of the table layouts:
Teams
Id,
Title,
CurrentTeamStatsId,
...
TeamStats
Id,
TeamId,
...
On the Entity for Team I have a navigation property called CurrentTeamStats which points to TeamStats so that I can get the most recent record easily. I Have the configuration as follows for that property:
entity.HasOne(c => c.CurrentTeamStats)
.WithOne(p => p.Team)
.HasForeignKey<Team>(c => c.CurrentTeamStatsId);
When I go to delete a team, an exception is being raised
Unable to save changes because a circular dependency was detected in the data to be saved
Any insight would be greatly appreciated.
Tried to configure the EF Core relationship differently, but same issue.
John Greco is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.