I'm sending both parent and its children to be updated to my service layer.
The model is set up as follows:
public class Parent
{
public int ParentId { get; set; }
public ICollection<Child> Children;
}
public class Child
{
public int ChildID {get; set;}
public virtual Parent Parent{get;set}
public virtual int ParentId{get; set;}
public string FirstName { get; set; }
}
The behaviour I'd like is that the children are always attached to the parent, so if a child is in the database that is not found attached, we should remove it. If it does not exist, create it. If it exist, update it.
How do I accomplish this without writing code to make all these calls manually? Like remove all, then re-add all.