I have the following:
public async Task<bool> Update(CoinEntity coinEntity)
{
var found = await context.Coins.FindAsync(coinEntity.CoinId);
if(found==null)
{
throw new CoinNotFoundException(coinEntity.CoinId);
}
Mapper.Initialize(cfg => cfg.CreateMap<CoinEntity, CoinEntity>());
found = Mapper.Map<CoinEntity>(coinEntity);
await context.SaveChangesAsync();
return true;
}
This works in sense that the found has all properties from the one passed in, however because the .Map creates a new instance, I assume. This is no longer being tracked by EFCore and SaveChanges has nothing changed.
Is there a way for automapper to actually update an actual object instead of creating a new instance?
I simply want my found
object to still be tracked by EF after automapper does its mapping.
I am trying to avoid having to copy field by field, and using .Attach of EF is not an option because it doesnt work since I need to replace child table records (deleting some, adding some)