C
C#2y ago
Oops365

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();
0 Replies
No replies yetBe the first to reply to this messageJoin