Oops
Oops
CC#
Created by Oops on 8/19/2022 in #help
AutoMapper.Collection.EFCore
Hey, I'm having trouble saving a nested collection using AutoMapper.Collection.EFCore. Specifically when I try to add a new item to a list, I get the exception below.
InnerException: ' is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached.
InnerException: ' is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached.
var parent = await _context.Parents.Include(p => p.ChildrenArray).FirstAsync(p => p.Sub == request.Sub);

// one of the nested properties is a List
_mapper.Map(request, parent);

// error here
await _context.SaveChangesAsync();
var parent = await _context.Parents.Include(p => p.ChildrenArray).FirstAsync(p => p.Sub == request.Sub);

// one of the nested properties is a List
_mapper.Map(request, parent);

// error here
await _context.SaveChangesAsync();
1 replies