So in a typical model where you have a parent that can have many children and a child that can have only one parent, how do you manage the adding of children. I have been u
I don't like all the extra AddXXX()
and RemoveXXX()
methods cluttering my entity interfaces. Instead, I have a custom list that raises events when the Add()
and Remove()
methods are called.
The linking then happens in the event handlers:
public class Course()
{
public Course()
{
this.Topics = new EntityList<Topic>();
this.Topics.AddItem += new AddItemEventHandler<Topic>(Topic_AddItem);
this.Topics.RemoveItem += new RemoveItemEventHandler<Topic>(Topic_RemoveItem);
}
public EntityList<Topic> Topics { get; private set; }
private void Topic_AddItem(Topic item, object args)
{
// Replace with your linking code:
EntityLinker.Link(this).With(item, args);
}
private void Topic_RemoveItem(Topic item, object args)
{
// Replace with your unlinking code:
EntityLinker.Unlink(this).From(item, args);
}
}