Base solution for your next web application
Open Closed

Updating an object which is within a list of items is deleting them instead of updating them #11148


User avatar
0
jtallon created
  • What is your product version? 10.2.0
  • What is your product type? Angular
  • What is product framework type? .net core

I have a parent entity with a list of child objects. On the UI I load up the parent screen with a list of child objects. I edit one of the child objects attributes. I call createOrUpdate on the parent object and pass everything correctly to the API.

I call parentRepository.GetAllIncluding(x=>x.children).FirstOrDefault( s=>s.Id == input.Id.Value);

I also call: ObjectMapper.Map(input, parentObject); var children = new List<LinkedChildren>(); ObjectMapper.Map(input.Children, children); parentObject.Children = children; await parentRepository.UpdateAsync(parentObject);

The Parent entity has public virtual List<LinkedChildren> Children { get; set; }

The Child entity has [Table("Children")] public class Children : FullAuditedEntity<Guid> { [Required] public virtual int ParentId { get; set; } [ForeignKey("ParentId")] public virtual Parent Parent { get; set; }

I can create the children however when I save after that the children become IsDeleted = 1


2 Answer(s)