What I try to reach is an NM relationship between AbstractUser and Plant in use with TPT inheritance.
When I try to configure the relationship,
modelBuilder.Entity<Plant>().HasMany(c => c.RemindedByUsers).WithMany().Map(m =>
{
m.ToTable("UserHasRemindedPlant");
});
I get the following exeption:
Additional information: Introducing FOREIGN KEY constraint 'FK_dbo.UserHasRemindedPlant_dbo.AbstractUsers_AbstractUser_Id' on table 'UserHasRemindedPlant' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
How do I set the ON DELETE or ON UPDATE action on many to many releationships on tpt abstract entities?
When I use the line above everything works fine but I need this convention for other entities.
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
Here my entity classes:
AbstractUser
public abstract class AbstractUser
{
protected AbstractUser()
{
RemindedPlants = new Collection<Plant>();
}
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
...
[Required]
public SchoolYear SchoolYear { get; set; }
public virtual ICollection<Plant> RemindedPlants { get; private set; }
}
Studend
[Table("Student")]
public class Student : AbstractUser
{
//some unrelevant props here
}
Teacher
[Table("Teacher")]
public class Teacher : AbstractUser
{
//some unrelevant props here
}