Looks like a "yet another EF multiple FK" question but please continue reading. I have the following requirements:
- A "Monitor" can have zero or more "Notifier"
- A "Monitor" can have zero or more "Setting"
- A "Notifier" can have zero or more "Setting"
So, deleting a "Monitor" will delete it's "Setting"s and "Notifiers". Also, since a "Notifier" may have zero or more Settings, related "Setting"s should be removed as well.
I have created the following model, but hit the famous "... may cause cycles or multiple cascade paths" error.
The closest answer was Entity Framework Cascading Delete but it uses DB first approach.
Can anyone suggest a workaround to enable cascaded deletes to above model?
And here is my model:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Testbed
{
public class Monitor
{
public int Id { get; set; }
[Column(TypeName = "varchar")]
[MaxLength(255)]
public string Type { get; set; }
[Column(TypeName = "varchar")]
[MaxLength(20)]
public string RunFrequency { get; set; }
public List<Setting> Settings { get; set; }
public List<Notifier> Notifiers { get; set; }
}
public class Setting
{
public int Id { get; set; }
[MaxLength(255)]
[Column(TypeName = "varchar")]
public string Name { get; set; }
[MaxLength(512)]
public string Value { get; set; }
public bool IsPassword { get; set; }
}
public class Notifier
{
public int Id { get; set; }
[MaxLength(255)]
[Column(TypeName = "varchar")]
public string Name { get; set; }
public List<Setting> Settings { get; set; }
}
}