Using the DTO template I grabbed from this forum I am using the ToEntity() Method to grab a JSON input from a Web Api input and convert that to an entity and then edit values in the parent and child of that entity.
DTO Template:
https://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=13256&HighLight=1
Since 5.5.1 and above when I try to edit the pk of the child (it is combination key), it will remove the entity from the graph. In the change log it appears that this was possibly addressed. (i.e pk changed entity might be out of sync, detach)
var task = newTaskEditModel.ToEntity<TaskDTO, TaskEntity>(true, true);
task.CustomNumber = _customNumberServices.GetNextCustomNumberLong(userDetails.TenantId, GetNextCustomNumberLongEnum.Task);
task.CreateDate = task.UpdateDate = currentUtc;
task.TableEntityTypeId = (short)EntityTypeEnum.Task;
task.TenantId = userDetails.TenantId;
if (!task.TaskStates.Any())
{
task.TaskStates.Add(new TaskStateEntity
{
Description = string.Empty,
EntityStateTypeId = (int)TaskEntityStateTypeEnum.NotStarted
});
}
var taskState = task.TaskStates.Single();
taskState.TenantId = userDetails.TenantId;
//since TenantId is part of the pk the entity will be removed from graph
taskState.CreateId = userDetails.UserId;
taskState.CreateDate = currentUtc;
taskState.TableEntityTypeId = (short)EntityTypeEnum.Task;
I have found that if I create a new child entity and then essentially clone it from the original child, then detach the original (detachFromGraph()), and then add the cloned one I get the expected results.
I have a bunch of code surrounding the editing of that pk and need some advice on what would be the suggestion solution, or if this is indeed a bug.
The combination primary key is basically for a multi-tenancy. pk = tenantId + pk of the entity.
Thanks for having a look,
Jon