I have the following fluent mapping:
modelBuilder.Entity<User>()
.HasMany<Device>(user => user.Devices)
.WithMany(sv => sv.Users)
.Map(userDevice =>
{
userDevice.MapLeftKey("UserId");
userDevice.MapRightKey("DeviceId");
userDevice.ToTable("UserDevice"));
});
Inside User:
public virtual ICollection<Device> Devices { get; set; }
Inside Device:
public virtual ICollection<User> Users { get; set; }
Now I receive the following error:
{"Introducing FOREIGN KEY constraint 'FK_dbo.UserDevice_dbo.Device_DeviceId' on table 'UserDevice' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.\r\nCould not create constraint. See previous errors."}
I would love to set "WillCascadeOnDelete(false)" but this option is not available on "WithMany()"
I also found the following solution but I do not want to disable cascade delete completely: Entity Framework Many to Many Cascade Delete Issue