-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
EF Core 5 many-to-many specify on delete no action #22803
Comments
@pantonis Can you give some details on why you would want to do this? For typical join tables. the two entities cannot be related if one of them does not exist. |
Because I have self referencing m2m and causes cyclic references |
@pantonis EF should build a model without cascading action by convention for self-referencing many-to-many relationships. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate. |
EF Team Triage: This issue is lacking enough information for us to be able to effectively triage it. In particular, it is missing the following information requested in the new issue template. Can you please provide this information?
Ideally include a complete code listing that we can run to reproduce the issue. Alternatively, you can provide a project/solution that we can run. BTW we're not just doing this to be mean 😄... we get a lot traffic on this project and it takes time to attempt to reproduce an issue based on fragments of information. In addition, our attempt is often unsuccessful as the exact conditions required to hit the issue are often not explicitly included in the code provided. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we ask that folks give us a self-contained way to reproduce an issue. For a guide on submitting good bug reports, read Painless Bug Tracking. BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions. |
Sorry for late reply. I simplified the database and I can't reproduce it anymore. |
Hi. I have gotten the same "may cause cycles or multiple cascade paths" error, and has made a project to show it. My 3 models are
When I try to run "Update-Database" I get this error.
The migration shows that they are set to cascade on delete
I could just remove the connection between the two classes I know, but I just want to know if it is intended to be like this. |
@isoap Since you have a relationship cycle in your model there's no good candidate for EF to make not cascade, so you'll have to choose one and configure it manually: protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<FloorRoutine>()
.HasMany(f => f.GymnastGroups)
.WithMany(g => g.FloorRoutines)
.UsingEntity<Dictionary<string, object>>(
"GymnastGroupFloorRoutine",
j => j.HasOne<GymnastGroup>().WithMany().OnDelete(DeleteBehavior.Cascade),
j => j.HasOne<FloorRoutine>().WithMany().OnDelete(DeleteBehavior.ClientCascade));
} We'll make this easier to do with #21535 |
Ask a question
In EF Core 5 many to many relationship I have a case that I need to specify Delete no action. How can I do that without creating the join table my self?
Include provider and version information
EF Core version: 5.0 RC2 Daily builds
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .Net Core 3.1
Operating system: Win 10
IDE: Latest VS2019
The text was updated successfully, but these errors were encountered: