© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago
Oops

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();
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

EFCore Updating an item after mapping with Automapper
C#CC# / help
4y ago
EFCore Collection Trying to save a duplicate.
C#CC# / help
2y ago
Dealing with collection type in MongoDb provider efcore
C#CC# / help
2y ago
❔ ✅ AutoMapper DI
C#CC# / help
3y ago