This error is being generated when I try to change a foreign key. I know this is a very common error I’ve found tons of information about it and tried to implement the fixe
I think you are trying to assign an ID when you need to assign the entity. (I'm not 100% sure this is what you are doing)
// Don't assign just the id
Person.ParentId = parentId;
// Assign the entity
Person.Parent = db.Parents.Single(x.Id == parentId);
For your second question , you can load all the sub_units by
var groups = db.sub_units.ToArray()
and once in memory do something like this:
foreach(var ticket in tickets)
{
ticket.assigned_to_group = groups.Single(f => f.id == assigned_to);
}