I have the following data model:
public class Bubble
{
public int Id { get; set; }
public string Name { get; set; }
public ICollection <Level> Children { get; set; }
}
public class Level
{
public int Id { get; set; }
public int BubbleId { get; set; }
public int? ParentId { get; set; }
public string Name { get; set; }
public Bubble Bubble { get; set; }
public Level Parent { get; set; }
public virtual ICollection<Level> Children { get; set; }
}
I want to store multiple sets of hierarchical data. Each set is owned by a bubble that contains levels (nodes). A level can either have it's self reference (parent) set to null (head of tree) or another level (sub node of parent) .
Now my problem is, that technically a level can have a parent (self reference) that does belong to another bubble. That should be impossible.
How can i make sure, that only levels with the same BubbleId FK can be assigned as a parent?
Id
andBubbleId
a composite primary key. – Gert Arnold Feb 21 '19 at 13:26