I have 3 entities; Groups, Scopes, Vlans
What I'm trying to accomplish:
- A Group can have many Scopes
- A Group can have many Vlans
- A Scope must have a Group
- A Vlan must have a Group
- A Scope can have a Vlan
- A Vlan can have a Scope
So kind of a soft relationship between vlans and scopes.
When not setting vlan or scope as a requirement EF complains about not knowing the principal of the relationship, So how do I fix this soft one to one relationship?
My Models:
public class Group
{
public Group()
{
Scopes = new HashSet<Scope>();
Vlans = new HashSet<VLAN>();
}
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public ICollection<VLAN> Vlans { get; set; }
public ICollection<Scope> Scopes { get; set; }
}
public class Scope
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public virtual VLAN Vlan { get; set; }
public virtual Group Group { get; set; }
}
public class VLAN
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public virtual Scope Scope { get; set; }
[Required]
public virtual Group Group { get; set; }
}